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 trialbaderbouta
7,804 PointsHow does this code look?
hey guys, I was wondering how this good looks to you and if I can do anything better.
//Start - Initial quiz score.
var correctAnswers = 0;
var uncorrectAnsewers =0;
//Questions.
var question1 = prompt("What is the name of the content layer in web development?");
if (question1.toUpperCase() === "HTML") {
correctAnswers += 1;
}
else {
uncorrectAnsewers += 1;
}
var question2 = prompt("What is the name of the behaviour layer in web development?");
if (question2.toUpperCase() === "JAVASCRIPT") {
correctAnswers += 1;
}
else {
uncorrectAnsewers += 1;
}
var question3 = prompt("how do we call a line of text in programming?");
if (question3.toUpperCase() === "STRING") {
correctAnswers += 1;
}
else {
uncorrectAnsewers += 1;
}
var question4 = prompt("How do we call a number in programming?");
if (question4.toUpperCase() === "INTEGER") {
correctAnswers += 1;
}
else {
uncorrectAnsewers += 1;
}
var question5 = prompt("How de we call a decimal number in programming?");
if (question5.toUpperCase() === "FLOAT") {
correctAnswers += 1;
}
else {
uncorrectAnsewers += 1;
}
//Outputs rank and crown based on number of correct answers given.
if (correctAnswers === 5) {
document.write("<h1> Congratulations! You have scored the maximum amount of of points and have been given a <bold>Gold crown.</bold> </h1>");
}
else if (correctAnswers >= 3) {
document.write("<h1> Congratulations! you have been given a <bold>Silver Crown.</bold> </h1>");
}
else if (correctAnswers >=2) {
document.write("<h1> You've done allright, take this <bold>Bronze Crown as a appreaciation</bold> </h1>");
}
else {
document.write("<h1> You've failed the quiz, try again... </h1>");
}
//Result
document.write("<h2> You've scored " + correctAnswers + " answers correctly and made " + uncorrectAnsewers +" mistakes!</h2>");
Thanks in advance!
1 Answer
Steven Parker
231,269 PointsAnother student posted a version of the same project just a few minutes ago that you could look at just for style comparison. But your code is fine as-is.
As I mentioned to the other poster, the focus of this course is general language syntax, vocabulary, and common control structures. Building code that performs correctly is your objective for now. Later courses will cover techniques for optimization.
baderbouta
7,804 Pointsbaderbouta
7,804 PointsThank you, Steven!