Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
This video covers one solution to the first part of the "Build a Quiz" challenge.
Multidimensional array snippet
const questions = [
['How many planets are in the Solar System?', '8'],
['How many continents are there?', '7'],
['How many legs does an insect have?', '6'],
['What year was JavaScript created?', '1995']
];
The return value of the prompt()
method is always a string. If your question answers are numeric values, you'll need to convert the value of the response
variable to a number, otherwise the condition will always evaluate to false
.
The unary plus operator (+
) provides a quick way of converting a string to a number. Place a plus symbol just before the response
variable:
if ( +response === answer ) {
...
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up