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

David Shulkin
seal-mask
.a{fill-rule:evenodd;}techdegree
David Shulkin
Front End Web Development Techdegree Student 10,255 Points

If Anyone is having trouble...I have done my code challenge slightly different than Guil

Here is my code:

let correctGuess = false;


let rank = 0;

const main = document.querySelector("main");


let score = rank;

const first = prompt( "What color does blue and yellow make?" );

const second = prompt( "What is 2 + 4?" );

const third = prompt( "Who is the founder of Apple?" );

const fourth = prompt( "Where am I from?" );

const fifth = prompt( "What prescription makes your day go by fast" );

if ( first.toUpperCase() === "GREEN" ) { correctGuess = true; score = rank += 1; }

if ( second.toUpperCase() === "SIX" || second === "6" ) { correctGuess = true; score = rank += 1; }

if ( third.toUpperCase() === "STEVE JOBS" ) { correctGuess = true; score = rank += 1; }

if ( fourth.toUpperCase() === "INDIANA" ) { correctGuess = true; score = rank += 1; }

if ( fifth.toLowerCase() === "vyvance" ) { correctGuess = true; score = rank += 1; }

let message = ""

if ( rank === 5) { message = "Gold";

} else if ( rank === 3 || rank === 4 ) { message = "Silver";

} else if ( rank === 1 || rank === 2 ) { message = "Bronze";

} else { message = "No Crown"; }

main.innerHTML = <h2> You got ${rank} out of 5 questions correct</h2> <p>You earned: <strong>${message}</strong></p> ;

1 Answer

Hi David!

Your code was mostly correct.

Your biggest issue was not have backticks around your final innerHTML string (template literal syntax requires the string to be surrounded by backticks (the key above the tab key and to the left of the 1/! key - its uppercase value is the Tilda: ~

Actually, I see you probably included backticks, but they didn't display due the Markdown interpretation...

use three backticks javascript // code three backticks

For JS markdown...

My revised version of your code:

let correctGuess = false;

let rank = 0;

const main = document.querySelector("main");

let score = rank;

const first = prompt( "What color does blue and yellow make?" );

const second = prompt( "What is 2 + 4?" );

const third = prompt( "Who is the founder of Apple?" );

const fourth = prompt( "Where am I from?" );

const fifth = prompt( "What prescription makes your day go by fast" );

if ( first.toUpperCase() === "GREEN" ) { correctGuess = true; score = rank += 1; }

if ( second.toUpperCase() === "SIX" || second === "6" ) { correctGuess = true; score = rank += 1; }

if ( third.toUpperCase() === "STEVE JOBS" ) { correctGuess = true; score = rank += 1; }

if ( fourth.toUpperCase() === "INDIANA" ) { correctGuess = true; score = rank += 1; }

if ( fifth.toLowerCase() === "vyvance" ) { correctGuess = true; score = rank += 1; }

let message; // changed this - it's enough

if ( rank === 5) { message = "Gold";

} else if ( rank === 3 || rank === 4 ) { message = "Silver";

} else if ( rank === 1 || rank === 2 ) { message = "Bronze";

} else { message = "No Crown"; }


main.innerHTML = `<h2> You got ${rank} out of 5 questions correct</h2> <p>You earned: <strong>${message}</strong></p>`; // Notice the surrounding backticks

Note: backticks are this ` and not ' nor "

Other than that it seemed to work just fine.

I hope that helps.

Stay safe and happy coding!