[英]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.我正在使用 Math.cbrt,如果这是一个问题,我不是 100%,而是 Math.sqrt 试图将每个数字的平方根和立方根设为 100,我的代码将在下面。 Expected output is what is supposed to be output when every number has been calculated.计算完每个数字后,预期的 output 应该是 output。
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.您在 if 语句中设置number
的值。 You are not comparing values.您不是在比较值。
To compare two values, use this operator: ==
.要比较两个值,请使用此运算符: ==
。
ie: 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; };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.