Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Problem Statement
- =================
- Write a function min that takes two arguments and returns their minimum.
- */
- var min = function (val1, val2){
- if(!isNaN(val1) && !isNaN(val2)){
- if(val1 == val2){
- console.log('Both numbers are equal');
- }
- else if(val1 < val2){
- console.log(val1 + " is smaller than " + val2);
- }
- else{
- console.log(val2 + " is smaller than " + val1);
- }
- }
- else{
- console.log('One of the 2 values is not a number!');
- }
- }
- min(1,2);
- min(-1,2);
- min(2,1);
- min(2,-2);
- min(0,-1);
- min(0,0);
- min(1);
- min(1, 'lorem');
- /*
- Output
- ======
- "1 is smaller than 2"
- "-1 is smaller than 2"
- "1 is smaller than 2"
- "-2 is smaller than 2"
- "-1 is smaller than 0"
- "Both numbers are equal"
- "One of the 2 values is not a number!"
- "One of the 2 values is not a number!"
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement