I am getting an error that I am not able to figure, its about a function that takes an array and returns a random value from it. I used the same function last time and there was no such error
helpers.js
function choice(arr) {
let randomIndex = Math.floor(Math.random() * 3);
return arr[randomIndex];
}
export { choice };
box.js
import React, { Component } from 'react';
import {choice} from './helpers';
import './Box.css'
class Box extends Component {
static defaultProps = {
allColors: ["purple", "magenta", "violet", "pink"]
};
constructor(props){
super(props);
this.state = {color: choice(this.props.allcolors)};
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
}
render(){
return(
<div className="Box" style={{backgroundColor: this.state.color}
} onClick={this.handleClick}>
</div>
);
}
}
export default Box;
