For step 4 asks =
That’s not a very friendly way to display a color!
In Random, find the method named formatColor. This method transforms an rgb array into something a bit more readable.
Inside of the
, instead of simply using this.state.color, call the formatColor function and pass in this.state.color as an argument
When i apply this =
formatColor(ary) {
return ‘rgb(’ + ary.join(’, ') + ‘)’;
{this.formatColor(this.state.color)}
}
Nothing changes. Is this correct?
Thanks.
mtf
July 16, 2018, 3:34am
2
In order for us to make any contribution to this question we will need a link to the exercise that lets us try our hand at the code. Please post the URL, and any error messages that ensue, if any. Thank you.
Is this the page?
https://www.codecademy.com/en/courses/react-101/projects/random-color
1 Like
import React from ‘react’;
import ReactDOM from ‘react-dom’;
class Random extends React.Component {
componentDidMount() {
this.applyColor();
}
componentDidUpdate(prevProps, prevState) {
this.applyColor();
}
formatColor(ary) {
return ‘rgb(’ + ary.join(’, ') + ‘)’;
}
isLight() {
const rgb = this.state.color;
return rgb.reduce((a,b) => a+b) < 127 * 3;
}
applyColor() {
const color = this.formatColor(this.state.color);
document.body.style.background = color;
}
chooseColor() {
const random = [];
for (let i = 0; i < 3; i++) {
random.push(Math.floor(Math.random()*256));
}
return random;
}
render() {
return (
<h1 className={this.isLight() ? ‘white’ : ‘black’}>
</h1>
</div>
);
}
}
ReactDOM.render(
,
document.getElementById(‘app’)
);
this is the code i begin with
mtf
July 16, 2018, 4:03am
5
Can you find a way to make it more readable? There is something in New Users along those lines.
system
Closed
July 23, 2018, 4:03am
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.