简体   繁体   中英

So I'm trying to use Math.cbrt and my code isn't working as expected

I'm using Math.cbrt and I'm not 100% if this is a thing but Math.sqrt to try to get the The square root and cube roots of every number to 100, my code will be down below. Expected output is what is supposed to be output when every number has been calculated.

 let number = 1; let cube = Math.cbrt(number); let square = Math.sqrt(number); if(number = 100){ console.log("Roots completed your number has been delivered."); }else{ console.log(cube); console.log(square); number += 1; };

You are setting a value of number in the if statement. You are not comparing values.

To compare two values, use this operator: == .

ie:

 let number = 1; let cube = Math.cbrt(number); let square = Math.sqrt(number); if(number == 100){ console.log("Roots completed your number has been delivered."); }else{ console.log(cube); console.log(square); number += 1; };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM