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 trial
Chukudi Omar Osahor
5,023 PointsThis code is not running, and I'm not sure why..
//quiz begings with no questions answered
var correct = 0;
// questions
var questionOne = prompt('How many months are in a year?');
if (questionOne.toUpperCase() === 'TWELVE' || questionOne === '12'){
correct += 1;
}
var questionTwo = prompt('How many weeks are in a month?');
if (questionTwo.toUpperCase() === 'FOUR' || questionTwo === '4'){
correct += 1;
}
var questionThree = prompt('How many letters are in the word alphabet?');
if (questionThree.toUpperCase() === 'EIGHT' || questionThree === '8'){
correct += 1;
}
var questionFour = prompt('How many days are in a week?');
if (questionFour.toUpperCase() === 'SEVEN' || questionFour === '7'){
correct += 1;
}
var questionFive = prompt('How many minutes are in an hour?');
if (questionFive.toUpperCase() === 'SIXTY' || questionFive === '60'){
correct += 1;
}
// write results
document.write('<p>You answered ' + correct + 'questions correctly</p>');
// ranking
If (correct === 5){
document.write('<p><strong>You earned a gold crown</strong></p>');
} else if (correct >= 3) {
document.write('<p><strong>You earned a silver crown</strong></p>');
} else if (correct >= 1 {
document.write('<p><strong>You earned a bronze crown</strong></p>');
} else {
document.write('<p><strong>No crown for you today</strong></p>');
};
2 Answers
liam johnshon
Courses Plus Student 904 PointsHey chukudi , i found some mistakes which usually happens i mention those in comments
- small i in first condition
- missing bracket in third condition
if (correct === 5){ //error
document.write('You earned a gold crown');
} else if (correct >= 3) {
document.write('You earned a silver crown');
} else if (correct >= 1 ){ //error
document.write('You earned a bronze crown');
} else {
document.write('No crown for you today');
};
Thanks hope this help you !
rydavim
18,814 PointsI've changed your comment to an answer so that it may be voted on or marked as best answer.
Chukudi Omar Osahor
5,023 PointsRuns like a charm. JavaScript is unforgiving with typos )
rydavim
18,814 Pointsrydavim
18,814 PointsI've added some formatting to your code to make it easier to read. You can do this using the following markdown:
```language
your code here
```