* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
810 B
810 B
title
title |
---|
Use Advanced JavaScript in React Render Method |
Use Advanced JavaScript in React Render Method
Problem Explanation
While you are inside the render method and not inside the return method, you can write JavaScript without wrapping it inside curly braces.
First, you will have to set the constant 'answer' to a value. Access the 'possibleAnswers' array using the value of 'randomIndex', which is located within the state of your component. Remember, you access state using this.state
.
Solutions
Solution 1 (Click to Show/Hide)
const answer = possibleAnswers[this.state.randomIndex];
Next, insert your const 'answer' into the p-tags. Make sure to wrap it with curly braces { }
.
<p>
{answer}
</p>