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

Roy He
Roy He
997 Points

What's wrong with my Code?

I've typed the following code in, and not a single prompt shows up. What am I doing wrong?

var ansOne = prompt("What's 4 + 4");

var ansTwo = prompt("What's 2+2");

var ansThree = prompt("What's 9-4");

var ansFour = prompt("What's the Capital of Italy");

var ansFive = prompt("I'm greater than 3, less than 5");

var score = 0

if (parseInt(ansOne) === 8) { score += 1 }

if (parseInt(ansTwo) === 4) { score += 1 }

if (parseInt(ansThree) === 5) { score += 1 }

if (ansFour.toUpperCase === "ROME") { score += 1 }

if (parseFloat(ansFive) > 3 && parseFloat(ansFive) < 5) { score += 1 }

Antti Lylander
Antti Lylander
9,686 Points

I tried your code and got all the prompts on chrome. You are missing a semicolon at the end of the line where you declare var score though. After answering all the questions, I typed 'score' in the console and got 4, so everything seems to work fine.

1 Answer

Adam Beer
Adam Beer
11,314 Points

Hi! Please check this. toUpperCase() a function and after I use () . The end I use document.write . You wrote a good code.

var ansOne = prompt("What's 4 + 4");
var ansTwo = prompt("What's 2+2");
var ansThree = prompt("What's 9-4");
var ansFour = prompt("What's the Capital of Italy");
var ansFive = prompt("I'm greater than 3, less than 5");

var score = 0

if (parseInt(ansOne) === 8) { score += 1 }
if (parseInt(ansTwo) === 4) { score += 1 }
if (parseInt(ansThree) === 5) { score += 1 }
if (ansFour.toUpperCase() === "ROME") { score += 1 }
if (parseFloat(ansFive) > 3 && parseFloat(ansFive) < 5) { score += 1 }

document.write("You have " + score + " point(s) earned");