简体   繁体   English

我该如何解决这个问题? 使用Javascript

[英]How do I solve this ? Javascript

Here is the problem: 这是问题所在:

Declare a variable called x and assign it a value that equals the remainder of 20 divided by 3. Next, divide and assign 1 to that variable and display the result in an alert box. 声明一个名为x的变量,并为其赋值等于20除以3的余数。接下来,将该值除以1,并将结果显示在警告框中。 The result should be 2. 结果应该是2。

Here is my code: 这是我的代码:

var x = 20 / 3;
alert(x / 1);

I am brand new to Javascript. 我是Javascript的新手。 I am coming up with 6.66. 我想出6.66。 The answer should be 2. What am I doing wrong? 答案应该是2.我做错了什么?

You need this: 你需要这个:

the remainder of 20 divided by 3 剩余的20除以3

You're dividing . 你在分裂 The remainder (or modulo) operator in JavaScript is the percentage symbol ( % ). JavaScript中的余数(或模运算符)运算符是百分比符号( % )。

So your code should look like this instead: 所以你的代码应该是这样的:

 var x = 20 % 3; alert(x / 1); 

Further reading: 进一步阅读:

Well there is % in JS for remainder. 那么剩下的JS% / is the division sign. /是分裂标志。

 var x = 20 % 3; console.log(x / 1); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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