Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBailey Pownell
14,299 PointsPrompt won't open
For this challenge I came up with the following code. Unfortunately, the prompt won't open, even though the way I've set it up is very similar to how the instructor did it. Anyone know why? Thanks in advance!
var questionsRight = 0;
// question 1
var questionOne = prompt("What is 5 times 4?");
if (parseInt(questionOne) === 20) {
questionsRight = 1;
}
// question 2
var questionTwo = prompt("What is 7 times 11?");
if (parseInt(questionTwo) === 77) {
questionsRight = 1 + questionsRight;
}
// question 3
var questionThree = prompt("What is the capitol of the state of New York?");
if (questionThree.toUpperCase() = 'ALBANY') {
questionsRight = 1 + questionsRight;
}
// question 4
var questionFour = prompt("What is 48 divided by 6?");
if (parseInt(questionFour) === 8) {
questionsRight = 1 + questionsRight;
}
// question 5
var questionFive = prompt("What is the square root of 9?");
if (parseInt(questionFive) === 3 {
questionsRight = 1 + questionsRight;
}
document.write("You got ' + questionsRight + ' questions right out of five questions.");
if (questionsRight === 5) {
var rank = 'gold';
} else if (questionsRight >= 3 ) {
var rank = 'silver';
} else if (questionsRight >= 2 ) {
var rank = 'bronze';
} else {
var rank = 'no';
}
/* ranking notification */
document.write("You earned a ' + rank + ' crown.");
1 Answer
Justinas Vebra
1,053 PointsHi Bailey,
there are some syntax errors in your code:
- in question 3 you used assign operator in conditional statement instead of comparison operator (== or ===)
- in question 5 you forgot to close your condition with a bracket
Also, the syntax for printing out text with variables is wrong.
document.write("You got ' + questionsRight + ' questions right out of five questions.");
should be:
document.write("You got " + questionsRight + " questions right out of five questions.");
Bailey Pownell
14,299 PointsBailey Pownell
14,299 PointsThanks Justinas!