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 trialSteve Brown
2,781 PointsJavascript not loading
For whatever reason, the JavaScript is not loading in the preview workspace.
The HTML also appears to be normal: <script src="js/quiz.js"></script>
Snapshot: https://w.trhou.se/uinpkufqgi
/*
1. Store correct answers
- When quiz begins, no answers are correct
*/
let correct = 0;
// 2. Store the rank of a player
let rank;
// 3. Select the <main> HTML element
const main = document.querySelector("main");
/*
4. Ask at least 5 questions
- Store each answer in a variable
- Keep track of the number of correct answers
*/
const answer1 = prompt("Name a programming language that's also a gem.");
if ( answer1.toUpperCase() === 'RUBY' {
correct += 1;
}
const answer2 = prompt("Name a programming language that's also a gem.");
if ( answer2.toUpperCase() === 'PYTHON' {
correct += 1;
}
const answer3 = prompt("What language do you use to style web pages?");
if ( answer3.toUpperCase() === 'CSS' {
correct += 1;
}
const answer4 = prompt("What language do you use to build the structure of web pages?");
if ( answer4.toUpperCase() === 'HTML' {
correct += 1;
}
const answer5 = prompt("What language d you use to add interactivity to a web page?");
if ( answer5.toUpperCase() === 'JAVASCRIPT' {
correct += 1;
}
/*
5. Rank player based on number of correct answers
- 5 correct = Gold
- 3-4 correct = Silver
- 1-2 correct = Bronze
- 0 correct = No crown
*/
if ( correct === 5 ) {
rank = "Gold";
} else if ( correct >= 3 ) {
rank = "Silver";
} else if ( correct >= 2 ) {
rank = "Bronze";
} else {
rank = "None :(";
}
// 6. Output results to the <main> element
main.innerHTML = `
<h2>You got ${correct} out of five questions correct.</h2>
<p>Crown earned: <strong>${rank}</strong</p>
`;
1 Answer
Rohald van Merode
Treehouse StaffHey Steve Brown 👋
The JavaScript file is loading perfectly but looking at the console there is currently an error being thrown that stops your code from running:
Uncaught SyntaxError: Unexpected token '{'
You seem to be missing a couple of closing )
for your conditionals on lines 19, 23, 27, 31 and 35. After adding those the prompts should start showing up as expected 🙂
Hope this helps!