[Beta] Solution doesn't pass for challenge "React: Use Advanced JavaScript in React Render Method"
See original GitHub issueChallenge Name
https://beta.freecodecamp.org/en/challenges/react/use-advanced-javascript-in-react-render-method
Issue Description
Correct solution doesn’t pass. Maybe I am missing something but code does exactly what is asked in challenge description but last test doesn’t pass. “When text is entered into the input element and the button is clicked, the MagicEightBall component should return a p element that contains a random element from the possibleAnswers array.” - this test appears failed.
Browser Information
- Browser Name, Version: Chrome, Version 64.0.3282.140 (Official Build) (64-bit)
- Operating System: Windows 10
- Mobile, Desktop, or Tablet: Desktop
Your Code
const inputStyle = {
width: 235,
margin: 5
}
class MagicEightBall extends React.Component {
constructor(props) {
super(props);
this.state = {
userInput: '',
randomIndex: ''
}
this.ask = this.ask.bind(this);
this.handleChange = this.handleChange.bind(this);
}
ask() {
if (this.state.userInput) {
this.setState({
randomIndex: Math.floor(Math.random() * 20),
userInput: ''
});
}
}
handleChange(event) {
this.setState({
userInput: event.target.value
});
}
render() {
const possibleAnswers = [
"It is certain", "It is decidedly so", "Without a doubt",
"Yes, definitely", "You may rely on it", "As I see it, yes",
"Outlook good", "Yes", "Signs point to yes", "Reply hazy try again",
"Ask again later", "Better not tell you now", "Cannot predict now",
"Concentrate and ask again", "Don't count on it", "My reply is no",
"My sources say no", "Outlook not so good","Very doubtful", "Most likely"
];
const answer = possibleAnswers[this.state.randomIndex];
return (
<div>
<input
type="text"
value={this.state.userInput}
onChange={this.handleChange}
style={inputStyle} /><br />
<button onClick={this.ask}>Ask the Magic Eight Ball!</button><br />
<h3>Answer:</h3>
<p>
{answer}
</p>
</div>
);
}
};
Screenshot
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Use Advanced JavaScript in React Render Method - YouTube
In this React tutorial we use advanced JavaScript in React render method. This video constitutes one part of many where I cover the ......
Read more >Thinking in React
React is, in our opinion, the premier way to build big, fast Web apps with JavaScript. It has scaled very well for us...
Read more >Render Props - React
Render Props. The term “render prop” refers to a technique for sharing code between React components using a prop whose value is a...
Read more >Design Principles - React
If you see something wrong on the screen, you can open React DevTools, find the component responsible for rendering, and then see if...
Read more >You Might Not Need an Effect - React Docs
This tells React that you don't want the inner function to re-run unless either todos or filter have changed. React will remember the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Still a bug on main site. Its keeping me from passing this exercise.
I’m not sure what’s happening here, I tried taking a closer look at the last test (the one that always fails). And when logging the info used in the assert, it looks like it should pass…
The two conditions in the assert are true, and it still fails.
The test is complex and difficult to pinpoint what the problem is, or why it only seems to be failing in safari. By lowering the timeout at the beginning of the test from 250ms to 50ms it will pass some of the time, but still fail sometimes as well. I don’t know, that’s where I’m at.