Advertisement
3vo

Problem 5. The Biggest of 3 Numbers

3vo
Oct 25th, 2022
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.75 KB | Source Code | 0 0
  1. // Write a program that finds the biggest of three numbers.
  2. // Examples:
  3. // a     b    c    biggest
  4. //  5    2    2    5
  5. // -2   -2    1    1
  6. // -2    4    3    4
  7. //  0   -2.5  5    5
  8. // -0.1 -0.5 -1.1 -0.1
  9. let input = ['-0.1', '-0.5', '-1.1'];
  10. let print = this.print || console.log;
  11. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  12. // Get the numbers
  13. let a = Number(gets());
  14. let b = Number(gets());
  15. let c = Number(gets());
  16. // Find the biggest number with conditional statement
  17. if (a > b && a > c) {
  18.     console.log(a)
  19. } else if (b > a && b > c) {
  20.     console.log(b)
  21. } else if (c > a && c > b) {
  22.     console.log(c)
  23. }
  24. //Second option with The Math.max() function
  25. let biggestNum = Math.max(a, b, c);
  26. console.log(biggestNum);
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement