Arithmetic Apples Explainer

Arithmetic Apples Explainer

The aim of this puzzle:

Find an arithmetic error in the function multiplyApples and correct it. Remember that arithmetic errors happen when some part of the code’s mathematics are wrong, for example adding something inside of a function when it should be subtracting.

Walkthrough of the solution:

Dimitri’s function multiplyApples(12) should be multiplying the argument 12 by 3, however, with the current Starter Code:


function multiplyApples(students) {

return students / 3;

}

console.log(multiplyApples(12));

the output logged to the console is 4, which is not going to be a sufficient amount of apples for Dimitri’s students. To help visualize what’s going wrong, we could replace students in the function with the number 12:


return 12 / 3;

Because the function is dividing, we see that 12 / 3 = 4, which is incorrect output. This should be changed from (/) to (*) to multiply.

Sample code solution:

(Tap below to reveal)


function multiplyApples(students) {

return students * 3;

}

console.log(multiplyApples(12));