JavaScript: Get the highest number from three different numbers
JavaScript Math: Exercise-31 with Solution
Write a JavaScript function to get the highest number from three different numbers.
Test Data:
console.log(highest_of_three(-5, 4, 2));
4
Sample Solution:
JavaScript Code:
// Define a function named highest_of_three that returns the highest of three numbers.
function highest_of_three(num1, num2, num3)
{
// Use Math.max() to determine the maximum value among num1, num2, and num3.
return Math.max(num1, num2, num3);
}
// Output the result of finding the highest of -5, 4, and 2 to the console.
console.log(highest_of_three(-5, 4, 2));
Output:
4
Visual Presentation:
Flowchart:
Live Demo:
See the Pen javascript-math-exercise-31 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus.
Previous: Write a JavaScript function to cast a square root of a number to an integer.
Next: Write a JavaScript function to calculate the percentage (%) of a number.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/javascript-exercises/javascript-math-exercise-31.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics