DEV Community

Discussion on: Basic Algorithm Scripting in JavaScript

 
pentacular profile image
pentacular

In what case do you think you call Math.sign with a value less than one?

Thread Thread
 
toddster79 profile image
Todd Carlson

I'm using Math.sign() to check whether or not the number is positive or negative. If it never gets to my if statement, then how is it updating the variable and returning the string the correct number of times?

Thread Thread
 
toddster79 profile image
Todd Carlson

I guess I only call Math.sign for the positive case, the else statement returns the empty string for the other cases. I still don't see how this isn't a correct solution to the problem. I check to see if it is a positive number with Math.sign, if it is the variable gets updated and returned the correct number of times. In all other cases, negative or zero, it returns an empty string.

Thread Thread
 
pentacular profile image
pentacular

So, if (Math.sign(num)) { . . . } could be replaced with if (true) { ... } in your code without changing any answer?