mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
fix: different arithmetic operators in JS multiple choice questions (#57658)
This commit is contained in:
parent
4025aba7a3
commit
5b89dec411
@ -14,35 +14,76 @@ Watch the lecture video and answer the questions below.
|
||||
|
||||
## --text--
|
||||
|
||||
How can you check if a number is even using the `modulus` operator in JavaScript?
|
||||
Which of the following operators should you use to subtract one number from another?
|
||||
|
||||
## --answers--
|
||||
|
||||
Use the `modulus` operator and check if the remainder is equal to `0` using strict equality (`===`).
|
||||
|
||||
---
|
||||
|
||||
Use the `modulus` operator and check if the remainder is greater than `1`.
|
||||
`+`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider what remainder an even number gives when divided by `2`.
|
||||
Think about the symbol typically used for subtraction.
|
||||
|
||||
---
|
||||
|
||||
Use the `modulus` operator and ignore the remainder.
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider what remainder an even number gives when divided by `2`.
|
||||
`-`
|
||||
|
||||
---
|
||||
|
||||
Use the `modulus` operator and check if the remainder is equal to 1.
|
||||
`*`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider what remainder an even number gives when divided by `2`.
|
||||
Think about the symbol typically used for subtraction.
|
||||
|
||||
---
|
||||
|
||||
`/`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Think about the symbol typically used for subtraction.
|
||||
|
||||
## --video-solution--
|
||||
|
||||
2
|
||||
|
||||
## --text--
|
||||
|
||||
What’s the output of the following code?
|
||||
|
||||
```js
|
||||
const result = 4 / 0;
|
||||
console.log(result);
|
||||
```
|
||||
|
||||
## --answers--
|
||||
|
||||
`Infinity`
|
||||
|
||||
---
|
||||
|
||||
`4`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Recall the special value JavaScript returns when you divide by zero.
|
||||
|
||||
---
|
||||
|
||||
`1`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Recall the special value JavaScript returns when you divide by zero.
|
||||
|
||||
---
|
||||
|
||||
`16`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Recall the special value JavaScript returns when you divide by zero.
|
||||
|
||||
## --video-solution--
|
||||
|
||||
@ -50,71 +91,40 @@ Consider what remainder an even number gives when divided by `2`.
|
||||
|
||||
## --text--
|
||||
|
||||
Which of these statements best describes operator precedence in JavaScript?
|
||||
What’s the output of the following code?
|
||||
|
||||
```js
|
||||
const remainder = 5 % 3;
|
||||
console.log(remainder);
|
||||
```
|
||||
|
||||
## --answers--
|
||||
|
||||
Addition and subtraction have the highest precedence.
|
||||
`15`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider which operations are executed first in a mathematical expression.
|
||||
Remember that `%` is the remainder operator, so another way to think of the equation is, after `3` goes into `5` once, what’s left?
|
||||
|
||||
---
|
||||
|
||||
Exponentiation has the highest precedence, followed by multiplication, division, and remainder.
|
||||
`2`
|
||||
|
||||
---
|
||||
|
||||
Multiplication and division have lower precedence than addition and subtraction.
|
||||
`3`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider which operations are executed first in a mathematical expression.
|
||||
Remember that `%` is the remainder operator, so another way to think of the equation is, after `3` goes into `5` once, what’s left?
|
||||
|
||||
---
|
||||
|
||||
All operators have the same precedence.
|
||||
`1.6666666666666667`
|
||||
|
||||
### --feedback--
|
||||
|
||||
Consider which operations are executed first in a mathematical expression.
|
||||
|
||||
## --video-solution--
|
||||
|
||||
2
|
||||
|
||||
## --text--
|
||||
|
||||
How do you use the subtraction operator in JavaScript to find the difference between two numbers?
|
||||
|
||||
## --answers--
|
||||
|
||||
Use the plus sign (`+`) to subtract numbers.
|
||||
|
||||
### --feedback--
|
||||
|
||||
Think about the symbol typically used for subtraction.
|
||||
|
||||
---
|
||||
|
||||
Use the minus sign (`-`) to subtract a smaller number from a bigger number.
|
||||
|
||||
---
|
||||
|
||||
Use the multiplication sign (`*`) to perform subtraction.
|
||||
|
||||
### --feedback--
|
||||
|
||||
Think about the symbol typically used for subtraction.
|
||||
|
||||
---
|
||||
|
||||
Use the division sign (`/`) to find the difference.
|
||||
|
||||
### --feedback--
|
||||
|
||||
Think about the symbol typically used for subtraction.
|
||||
Remember that `%` is the remainder operator, so another way to think of the equation is, after `3` goes into `5` once, what’s left?
|
||||
|
||||
## --video-solution--
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user