[PENDING] Error When Squaring 1

Learn How to Code: Basics of Programming I: Data Types

Course URLs:
https://www.codecademy.com/courses/learn-how-to-code/lessons/bop-datatypes/exercises/datatypes-all-together
https://www.codecademy.com/courses/learn-how-to-code/lessons/bop-datatypes/exercises/review

On exercises 5 and 6 (Putting it All Together and Data Types Review) of the Data Types lesson, when attempting to call the Square function on myNumber = 1, it throws the error ERROR Input is not number. If myNumber is assigned any value (including all negative numbers) other than 1 or 0, it works.

This issue has also been mentioned here:

2 Likes

So if we inspect the element of sketch.js we find these lines

      if(myNumber == true) throw "\nnot number"
      if(myNumber == false) throw "\nnot number"

which I think represent the problem you’re talking about (1 or 0, since 1 and 0 evaluate as true and false respectively)

let test = true;
console.log(test==1);
// true

See the code below:


  if (programChoice == 'square'){
    try {
      if(myNumber == "") throw "\nnot number";
      if(isNaN(myNumber)) throw "\nnot number";
      if(myNumber !== Number(myNumber)) throw "\nnot number";
      if(myNumber == true) throw "\nnot number"
      if(myNumber == false) throw "\nnot number"

function squareNumber(number){
  return (number*number)
}
1 Like

Ah, yes, that must be it. Should I be taking down this topic then?

1 Like

No this is perfect, they should fix it. I don’t work for them :slight_smile:

1 Like

As soon as I saw the problem only affected 1 and 0 and was JS based, I thought it was likely a truthy/falsey test failure.

I’ll pass this along. :slight_smile:

2 Likes