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 trialWameedh Mohammed Ali
16,572 PointsMy code for the quiz challenge
Hey all, Here is my code for the quiz challenge, I would like to share it with you!
/*
Ask at least five questions
Keep track of the number of questions the user answered correctly
Provide a final message after the quiz letting the user know the number of questions he or she got right.
Rank the player. If the player answered all five correctly, give that player the gold crown: 3-4 is a silver crown; 1-2 correct answers is a bronze crown and 0 correct is no crown at all.
*/
//5 questions of the our quiz
var question1 = prompt("Do you love JavaScript?");
var question2 = prompt("Do you love Computers?");
var question3 = prompt("Do you love Soccer?");
var question4 = prompt("Do you love Baghdad?");
var question5 = prompt("Do you love Starbucks?");
//Empty var for the score
var score = 0;
//Empty var for the prise
var prise = "";
//Count the answers and give score to the player
if (question1 === "yes" || question1 === "y") {
score += 1;
}
if (question2 === "yes" || question2 === "y") {
score += 1;
}
if (question3 === "yes" || question3 === "y") {
score += 1;
}
if (question4 === "yes" || question4 === "y") {
score += 1;
}
if (question5 === "yes" || question5 === "y") {
score += 1;
}
//Check the Rank of the player!
if (score === 5) {
prise = "Gold crown";
} else if (score === 4 || score === 3){
prise = "Silver crown";
}else if (score === 2 || score === 1){
prise = "Bronze crown";
} else {
prise = "No crown at all";
}
// our final message telling the score and the price
document.write("Your score is: " + score + "<br>Your prise is: " + prise);
Cheers!
Wameedh
Wameedh Mohammed Ali
16,572 PointsThanks Mark!
3 Answers
Mark Casavantes
Courses Plus Student 13,401 PointsHi Chyno and Wameedh,
If Wameedh is studying HTML he will not see arrays until he studies JavaScript or some other language. I like your excellent attitude Wameedh!
Excellent point Chyno about using an array. I got a little experience with arrays working on codeabbey.com problems for practice. It took me a while to figure out how to set them up and make them work.
Chyno Deluxe
16,936 PointsIt takes practice but it's important to challenge yourself in order to become better.
Wameedh Mohammed Ali
16,572 PointsThank you Mark, This is motivated me more. I saw your website it is great what you are doing and heading to. I wish you all the best and more success which you are! Are you a self-taught?
Chyno your work is awesome. You have a great future as a front-end web developer. The UI in your work, Is your work as well?
Cheers!
Chyno Deluxe
16,936 PointsWameedh, Thank you for taking the time to check out my work. My website's theme is not my creation but the projects within my site are. The projects on my codepen however are entirely mine.
Chyno Deluxe
16,936 PointsNice! Now can you take it a step further and create an array with all the questions and answers and cycle through them using a for loop?
Wameedh Mohammed Ali
16,572 PointsI don't know how to create an array yet, but when I will learn I going to make this as a challenge to me and show it to you!
Thanks though!
Mark Casavantes
Courses Plus Student 13,401 PointsGood Morning Chyno and Wameedh,
Yes, I am self-taught. Learning to web design and computer program is hard work. I am thinking of auditing some local computer programming and web design classes. I hope to meet web designers and computer programmers from my area. (West Texas and Southern New Mexico). I would like to do a part-time internship with a firm in my area as well to gain real world experience and be able to discuss web design and computer programming in order to improve my skills..
I also want to help others on Treehouse to do well. I look for problems and situations that I can provide assistance. When I first started, I had a real hard time. I think there needs to be a level below Beginner to introduce those with very little experience. If I can help you both, let me know.
Have a Great Day!
Mark
Mark Casavantes
Courses Plus Student 13,401 PointsMark Casavantes
Courses Plus Student 13,401 PointsGood Job Wameedh!