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

Mitchell Kienhuis
Mitchell Kienhuis
2,507 Points

Why won't my code run, it runs fine till I added like question 3 and above.....

HEEEELPPPPP ;'( Here a snap to my code: https://w.trhou.se/xtfl21a1ro

1 Answer

Michael Collins
Michael Collins
3,447 Points

You have a few errors which is why it isn't running.

Firstly, if you go to your 'index.html' file, you have the 'quiz.js' script added to the page twice. You should remove the top one and move the one near the bottom so it is just above the closing </body> tag, rather than inside the .container div. Having it on the site twice means the script is running twice.

You also have a few syntax errors in your quiz.js file. If you go to the page in your browser and look at the developer tools, it will tell you which lines these are on and what the errors are.

On line 75, you are missing a closing bracket after '( month and year?'. It should be ( month and year?)

Then further down the file you have assigned a value to your medal variable using document.write. However, you just want to assign a value to the variable and not the document.write method. You are outputting the value of the medal variable to the page using the document.write method later in your script on line 105.

Also, in this block of code you are using:

if(score === 100) {
    var medal = document.write(<h2>GOLD?</h2>);
} if else(score === 80) {
    var medal = document.write('<h2>SILVER ?</h2>');
} if else(score === 60) {
    var medal = document.write('<h2>Bronze</h2>');                           
} else {
    var medal = document.write('nothing');
}

However, the statement should be if, else if, else so:

if(score === 100) {
    var medal = 'GOLD?';
} else if(score === 80) {
    var medal = 'SILVER ?';
} else if(score === 60) {
    var medal = 'Bronze';                           
} else {
    var medal = 'nothing';
}

Once these errors are fixed, your quiz should work.

Hope it helps.

EDIT.

To make the last bit of code a bit cleaner, you should also declare the medal variable at the top of your script as you have done with your other variables.

    var medal;

Then your last bit of code could just be written as:

if(score === 100) {
    medal = 'GOLD?';
} else if(score === 80) {
    medal = 'SILVER ?';
} else if(score === 60) {
    medal = 'Bronze';                           
} else {
    medal = 'nothing';
}