Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /*
  2. Problem Statement
  3. =================
  4.  
  5. Write a function min that takes two arguments and returns their minimum.
  6. */
  7.  
  8. var min = function (val1, val2){
  9. if(!isNaN(val1) && !isNaN(val2)){
  10. if(val1 == val2){
  11. console.log('Both numbers are equal');
  12. }
  13. else if(val1 < val2){
  14. console.log(val1 + " is smaller than " + val2);
  15. }
  16. else{
  17. console.log(val2 + " is smaller than " + val1);
  18. }
  19. }
  20. else{
  21. console.log('One of the 2 values is not a number!');
  22. }
  23. }
  24.  
  25. min(1,2);
  26. min(-1,2);
  27. min(2,1);
  28. min(2,-2);
  29. min(0,-1);
  30. min(0,0);
  31. min(1);
  32. min(1, 'lorem');
  33.  
  34. /*
  35. Output
  36. ======
  37.  
  38. "1 is smaller than 2"
  39. "-1 is smaller than 2"
  40. "1 is smaller than 2"
  41. "-2 is smaller than 2"
  42. "-1 is smaller than 0"
  43. "Both numbers are equal"
  44. "One of the 2 values is not a number!"
  45. "One of the 2 values is not a number!"
  46. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement