Asd;cjnasdn asdklcnasdkl;cn as;cfmn;alc;

asdlfnaskd asdlkfnc;asdncfa asdbnlkasdncf

var x; // x: undefined
var result; // x: undefined, result: undefined
if (0 <= x < 9) {

On that last line, two things. One, it’s invalid JavaScript - unfortunately you can’t string together comparators like this. It would need to be rewritten like this:

0 <= x && x < 9

Second, even if you rewrite it as above, x will always be undefined since you haven’t assigned it a value anywhere. So your result never gets assigned a value either.

Why did you add that if statement? What do you think it is doing to help you? (totally serious questions. You should always be asking yourself what your code is doing for you.)


see, it works, nothing is invalid!
Just one instruction isnt working.

This is the console output when i run my code:
Since it is returning a whole number which means code works.

A minute ago I made it work completely with no issue see:

var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function randomWholeNum() {

// Only change code below this line

var x;

var result;

if (0 <= x < 9) {

result = Math.floor(Math.random() * 10);

return result;




My code is lengthy, but u cant expect perfection from a beginner!

Sorry, I should have been more specific with my breakdown of 0 <= x < 9.

JavaScript evaluates operators left to right, so the first operation in this expression is <=, then uses that result as the left side of the < operation.

0 <= x < 9 // x is undefined so plug that in
0 <= undefined < 9 // evaluate 0 <= undefined
false < 9 // evaluates to true

This runs, but it logically makes no sense. Why are you comparing undefined with numbers?

In plain English, here’s what your function does:

  1. Create a variable named x, don’t set its value (implicitly undefined)
  2. Create a variable named result, don’t set its value (implicitly undefined)
  3. If the boolean result of 0 <= x is less than 9:
    • assign result a random integer from 0 to 9
    • return result

As @JeremyLT asked, what is the point of the if statement?

1 Like

That (0 <= x < 9) thing works in Python, but in JS it’s as @colinthornton described it. It’s an unfortunate fact of JS’s loose type system that it doesn’t bomb with an error. Pretty sure Typescript will reject it though.

1 Like

asdlkasdkln asdfnas;dlfnmas s;dmnf;sdl