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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

I have done the challenge somewhat different from the teacher

My javascript is a bit different have i still got it right?

var percentage, threeCubed, cubeEdges, chessBoard, diceDots;
var correct = 0;

percentage = prompt("What is 20% of 40?"); // 8
threeCubed = prompt("How much is three cubed?"); // 27
cubeEdges = prompt("How many edges does a cube have?"); // 12
diceDots = prompt("How many dots are there in total on a pair of dice?"); // 42
chessBoard = prompt("How many squares are there on a chess board?"); // 64

if (parseInt(percentage) === 8 || percentage.toLowerCase() === "eight") {
    correct += 1;
}

if (parseInt(threeCubed) === 27 || threeCubed.toLowerCase() === "twenty seven") {
    correct += 1;
}

if (parseInt(cubeEdges) === 12 || cubeEdges.toLowerCase() === "twelve") {
    correct += 1;
}

if (parseInt(diceDots) === 42 || diceDots.toLowerCase() === "fourty two") {
    correct += 1;
}

if (parseInt(chessBoard) === 64 || chessBoard.toLowerCase() === "sixty four") {
    correct += 1;
}

document.write("You have answered " + correct + " questions correctly. <br>");

if (correct === 5) {
    document.write("You have won a gold trophy");
} else if ( correct === 4 || correct === 3 ) {
    document.write("You have won a silver trophy");
} else if ( correct === 2 || correct === 1 ) {
    document.write("You have won a bronze trophy");
} else {
    document.write("You didnt get a trophy. Try again next time");
}

1 Answer

Steven Parker
Steven Parker
231,007 Points

Looks great, good job! :+1:

There are always options in programming. it's fine for your solution to be different as long as it works the same, and is not significantly larger or more complex than the teacher's.

I used the "or" conditional statements as opposed to the "bigger or equal to" condition and it worked great!

Steven Parker
Steven Parker
231,007 Points

It does work exactly the same. The only advantage of the original version is the code is slightly more compact.