Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
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 up-
Sufiyaan Haroon
Full Stack JavaScript Techdegree Student 9,558 Points3 Answers
-
Dennis Trinidad
Full Stack JavaScript Techdegree Student 759 Points1 Answer
-
Samuel Kleos
Front End Web Development Techdegree Student 13,728 Points1 Answer
-
Micah Angelica Baguio
3,409 Points1 Answer
-
sasha shveps
842 Points1 Answer
-
Michael Arasimowicz
Full Stack JavaScript Techdegree Student 1,794 PointsBuild a Quiz 1 Solution
1 Answer
-
Hina K.
4,807 Points1 Answer
-
Naoki Yoshida
6,984 PointsMy answers are strings. ".toLowerCase" doesn't work.
Posted by Naoki YoshidaNaoki Yoshida
6,984 Points1 Answer
-
Alex Hort-Francis
17,074 Points0 Answers
-
Paige Christensen
Data Analysis Techdegree Student 3,706 Points1 Answer
-
ivan dolgonos
Full Stack JavaScript Techdegree Student 4,195 Points1 Answer
-
PLUS
Anica Bell
Courses Plus Student 3,004 Points3 Answers
-
Tamella Hajiyeva
Full Stack JavaScript Techdegree Student 6,678 Points1 Answer
-
Clayton Bailey
1,453 Points1 Answer
-
Zowie Erickson
Front End Web Development Techdegree Graduate 16,203 Points2 Answers
-
Cheryl Chao
5,555 Points1 Answer
View all discussions for this video
Related 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