So I'm trying to run a simple "conditional statement exercise" with a few questions, but in my Google Chrome it keeps giving me an error. Other applications aren't giving me any errors. I also have the most updated version of Google Chrome
Warning the js is going to launch when you go to the link
Check out my js fiddle
var counter = 0;
var questions = 5;
var ready = false;
alert("I have " + questions + " questions to ask you?");
var name = prompt("What is your name?");
alert("Hello " + name + "!");
alert("Here we go!");
var answer1 = prompt(name + "What color is the sky?");
if (answer1.toUpperCase() === 'BLUE') {
counter += 1;
alert('Congrates ' + name + ' you were right!');
} else {
alert('Sorry' + ' ' + name + 'but that was wrong.');
}
So I'm trying to run a simple "conditional statement exercise" with a few questions, but in my Google Chrome it keeps giving me an error. Other applications aren't giving me any errors. I also have the most updated version of Google Chrome
Warning the js is going to launch when you go to the link
Check out my js fiddle
var counter = 0;
var questions = 5;
var ready = false;
alert("I have " + questions + " questions to ask you?");
var name = prompt("What is your name?");
alert("Hello " + name + "!");
alert("Here we go!");
var answer1 = prompt(name + "What color is the sky?");
if (answer1.toUpperCase() === 'BLUE') {
counter += 1;
alert('Congrates ' + name + ' you were right!');
} else {
alert('Sorry' + ' ' + name + 'but that was wrong.');
}
Share
Improve this question
asked Nov 19, 2014 at 2:05
EliCollinsEliCollins
891 silver badge8 bronze badges
3
- Is working ok for me in chrome38 – ianaya89 Commented Nov 19, 2014 at 2:07
-
Cannot read property 'toUpperCase' of null
- do not press Cancel button. Or assign the return ofprompt
to variable and check if it is a boolean or a string before applyingtoUpperCase
function - only strings have it. – Cheery Commented Nov 19, 2014 at 2:11 - When I launched the "app" I didn't press cancel but I guess I have to to wrap the conditional in a conditional to get to fully work on a my version of chrome??? – EliCollins Commented Nov 19, 2014 at 2:41
1 Answer
Reset to default 5I'm not seeing that error. You can try wrapping that conditional in a value check conditional:
var answer1 = prompt(name + "What color is the sky?");
if (answer1) {
if (answer1.toUpperCase() === 'BLUE') {
counter += 1;
alert('Congrates ' + name + ' you were right!');
} else {
alert('Sorry' + ' ' + name + 'but that was wrong.');
}
}