Javascript error lesson 15 & 16


#1

See lesson 15. The first image. The "if"number is totally wrong but it's telling me that it is right and I can go to the next lesson. Here's the code:

if ("5>100" )
{
console.log("Let's go down the first road!");
}
else
{
// What should we do if the condition is false? Fill in here:
console.log("Nooooooo")
}

5 is definitely not larger than 100 but the message it shows me is "Let's go down the first road!" not "Noooo".

The 2nd image is me trying to replicate the code from the 1st image. Everything works well, the answers match up to my "if" but it is showing an error saying: Oops, try again. It looks like your if/else statement didn't log "The condition is false" to the console.
Here's the code:

if (5>1)

{
console.log("yes!")
}

else

{

console.log("no!")

}

Help?

Uploading...
Uploading...


#2

The above is a plain string, or primitive. It is not a boolean expression as one might surmise. Just a string. It has a length greater than zero. In an if statement conditional argument it evaluates to true.


#3

You are not answering my question. The first code 5>100 is from code academy. I just copied the first code (from lesson 15) to the second code (lesson 16) where I was supposed to make my own.

Tell me what's wrong with

if (5>1)

{
console.log("yes!")
}

else

{

console.log("no!")
}

Why is it showing an error?


#4

At the end of your console.log statements there are no semicolons. Console.log needs a semicolon to run.


#5

Not so. The semi-colon is just syntax. A linter will only raise a caution, not a warning. The code works no matter what.


#6

If your condition is true, use console.log to print "The condition is true".

Otherwise (else) when it is false, use console.log to print "The condition is false".

Make sure your condition evaluates to false, so that your program prints out "The condition is false".


#7

if(10<3)
{
console.log("we aren't going to see this one!");
}
else
{
console.log("you know your math!");
}

IS my code, and it's saying my first if statement isn't producing a false????


#8

Last time I checked 10 was not less than 3. So it should be giving a false response, but it's not for some reason.


#9

2 posts were split to a new topic: Punctuation help


#10