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
Diamond Black
5,942 PointsMy take on The Conditional Challenge.
/*
Ask atleast 5 questions
Keep track of # ofcorrect answers
Let user know how much correct
Rank player
*/
var reward = 0
var ans1 = 365
var ans2 = 60
var ans3 = 52
var ans4 = 1440
var ans5 = 24
var ques1 = prompt("How many days in a year?");
if (parseInt(ques1) === ans1) {
reward += 1;
}
var ques2 = prompt("How many minutes in a hour?");
if (parseInt(ques2) === ans2) {
reward += 1;
}
var ques3 = prompt("How many weeks in a year?");
if (parseInt(ques3) === ans3) {
reward += 1;
}
var ques4 = prompt("How many minutes in a day?");
if (parseInt(ques4) === ans4) {
reward += 1;
}
var ques5 = prompt("How many hours in a day?");
if (parseInt(ques5) === ans5) {
reward += 1;
}
document.write("<fontsize=40>You got " + reward + " right out of 5.</fontsize>");
if (reward === 5) {
alert("Congrats you scored " + reward + " points. You earned a gold crown!");
} else if (reward >= 3 ) {
alert("Congrats you scored " + reward + " points. You earned a silver crown");
} else if (reward >= 1 ) {
alert("Congrats you scored " + reward + " points. You earned a bronze crown");
} else {
alert("Sorry you did not score any points. Try again!!!");
}
2 Answers
Chyno Deluxe
16,936 PointsGreat job!
The only thing I would change on your code is the document.write fontsize. I would recommend changing it to an h1 tag if you would want a large font. View below
document.write("<h1>You got " + reward + " right out of 5.</h1>");
Of course, there is always room to improve your code by learning more about loops, arrays and keeping your code D.R.Y. but you have done a great job so far.
Diamond Black
5,942 PointsThank You Chyno. Defintely will try that.