简体   繁体   English

所以我正在尝试使用 Math.cbrt 并且我的代码没有按预期工作

[英]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.

相关问题 为什么我的 JS 代码不工作? 我正在尝试获取此代码以生成随机密码 - Why isn't my JS code working? I'm trying to get this code to generate a random password 我正在尝试将数字提高到其连续的功效,而我的代码不起作用 - I'm trying to raise numbers to their consecutive powers and my code isn't working 为什么Math.cbrt(1728)产生的结果比Math.pow(1728,1 / 3)更准确? - Why does Math.cbrt(1728) produce a more accurate result than Math.pow(1728, 1/3)? 我试图找出两个 arrays 之间的区别,但我的代码对 0 不起作用有什么建议吗? - I'm trying to find the difference between two arrays but my code isn't working for 0s any advice? 如何在不使用 Math.cbrt() 函数的情况下在 JavaScript 中计算立方根? 如何用递归计算? - How to calculate cube root in JavaScript without using Math.cbrt() function ? How to Calculate with recursion? 我正在尝试使用nameInput的值更新div元素,我的代码对吗? - I'm trying to update my div element with the value of my nameInput, isn't my code right? 我如何正确使用promise,以便我的代码不会嵌套? - How can I properly use promises so my code isn't so nested? 当我使用 fetch my.then 代码不起作用 - When I use fetch my .then code isn't working 我正在尝试使用简单的网络摄像头捕获上传,上传不起作用? - I'm trying to use a simple webcam capture upload, upload isn't working? 为什么我的javascript / jquery代码不能像复选框那样工作 - Why isn't my javascript/jquery code working as expected for checkboxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM