Skip to content

Instantly share code, notes, and snippets.

@sethschori
Forked from anonymous/Round Town (1.2).js
Created July 31, 2016 17:07
Show Gist options
  • Save sethschori/cbfc280825725be1304d10916e9feca0 to your computer and use it in GitHub Desktop.
Save sethschori/cbfc280825725be1304d10916e9feca0 to your computer and use it in GitHub Desktop.
https://repl.it/CTRj/46 created by sethopia
/*
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));
Native Browser JavaScript
>>> 31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment