question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Beta] Solution doesn't pass for challenge "React: Use Advanced JavaScript in React Render Method"

See original GitHub issue

Challenge 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

react-use-advanced-javascript-in-react-render-method

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ajhernandez95commented, Jul 11, 2018

Still a bug on main site. Its keeping me from passing this exercise.

0reactions
moT01commented, Dec 21, 2019

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…

Screen Shot 2019-12-21 at 9 21 02 AM Screen Shot 2019-12-21 at 7 36 32 AM

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found