Created
July 31, 2016 17:07
-
-
Save anonymous/f9dbfc40c9577e138ab87e33b647983d to your computer and use it in GitHub Desktop.
https://repl.it/CTRj/46 created by sethopia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ROUND TOWN | |
We will look at 3 Math functions in some depth: | |
Math.floor(x) | |
Math.ceil(x) | |
Math.round(x) | |
Math.floor() returns the largest integer less than or equal to a given number. | |
ex) | |
Math.floor(13.45) ==> 13 | |
Math.ceil() returns the largest integer greater than or equal to a given number. | |
ex) | |
Math.ceil(13.45) ==> 14 | |
Math.round() rounds to the nearest integer | |
ex) | |
Math.round(13.45) ==> 13 | |
Math.round(-214.55) ==> -215 | |
Create a function sumMultiplyAndRound that takes 3 numbers. The function should sum the first two numbers passed in, round them down to the nearest integer. The rounded sum should then be multiplied by the third argument, rounded up and returned. | |
ex) | |
sumMultiplyAndRound(2, 3.5, 6.2) ==> 31 | |
*/ | |
function sumMultiplyAndRound(n1,n2,n3) { | |
return Math.ceil((n3*(Math.floor(n1+n2)))); | |
} | |
console.log(sumMultiplyAndRound(2, 3.5, 6.2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
>>> 31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment