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

question

is there anything wrong with this code? var correctAnswers = 0; var talking = prompt("when donald trump ruled America?."); if (parseInt(talking.toUpperCase) == 2016){ correctAnswers=+1; }else{ alert("sorry you've got it wrong") } var talking_1 = prompt("who's the CEO of google?"); if (talking_1.toUpperCase === "sundar pichai"){ correctAnswers=+1; }else{ alert("sorry you've got it wrong"); } var talking_2 = prompt("what is the Biggest oceans in the earth"); if (talking_2.toUpperCase === "pacific ocean"){ correctAnswers=+1; }else{ alert("sorry you've got it wrong"); } var talking_3 = prompt("who made facebook?"); if (talking_3.toUpperCase === "michael zuckberg"){ correctAnswers=+1; }else{ alert("sorry you've got it wrong"); } var talking_4 = prompt("who made DropBox?"); if (talking_4.toUpperCase === "dave zuckberg"){ correctAnswers=+1; }else{ alert("sorry you've got it wrong"); }

Steven Parker
Steven Parker
231,271 Points

When posting code, be sure to use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" section. :arrow_heading_down:

Also, please describe the issues you are having with the code.

2 Answers

Hi there!

If you look at how you're increasing your score each question:

correctAnswers = +1;

This is actually assigning the value positive one to the variable and replacing whatever was in it, not adding to it. the shorthand for variable = variable + 1 would be:

someVal += 1

Also have a look at that first question - you call capitalize on a string you'll then pass to parseInt to ensure it's a number ;)

Hope it helps!

PS as Steve said, if you put your code wrapped in 3 backticks like this:

```javascript
// Your JavaScript code here...
```

Then if will appear formated and easy to read, like this:

var correctAnswers = 0;
var talking = prompt("when donald trump ruled America?.");
if (parseInt(talking) == 2016) {
    correctAnswers = +1;
} else {
    alert("sorry you've got it wrong")
}
var talking_1 = prompt("who's the CEO of google?");
if (talking_1.toUpperCase === "sundar pichai") {
    correctAnswers = +1;
} else {
    alert("sorry you've got it wrong");
}
var talking_2 = prompt("what is the Biggest oceans in the earth");
if (talking_2.toUpperCase === "pacific ocean") {
    correctAnswers = +1;
} else {
    alert("sorry you've got it wrong");
}
var talking_3 = prompt("who made facebook?");
if (talking_3.toUpperCase === "michael zuckberg") {
    correctAnswers = +1;
} else {
    alert("sorry you've got it wrong");
}
var talking_4 = prompt("who made DropBox?");
if (talking_4.toUpperCase === "dave zuckberg") {
    correctAnswers = +1;
} else {
    alert("sorry you've got it wrong");
}

Thank you very much for your answer, jon mirow but i have another question, How do i fix this problem? when i preview the results and i type in the right answer it say's to me that i'm wrong, for example

like this question:When donald trump ruled america? and i say 2016 and it says that i'm wrong what's wrong with this code?

and if you don't know that what did i type in the workspace. here's the code==>

var talking = prompt("when donald trump ruled America?.");
if (parseInt(talking) == 2016) {
correctAnswers = +1;
} else {

Hmm, I can't replicate that error on that code sorry.

I've added two alerts to your code above to demonstrate:

var talking = prompt("when donald trump ruled America?.");
if (parseInt(talking) == 2016) {
correctAnswers = +1;
alert("right");
} else {
alert("wrong");
}

If you copy that, press ctrl+shift+j in your browser and paste that into the console then hit return, you should see that it is working. Are you sure it's this question that isn't working in your workspace?