w3resource

JavaScript: Get the highest number from three different numbers

JavaScript Math: Exercise-31 with Solution

Highest of Three Numbers

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:

JavaScript: Math - Get the highest number from three different numbers.

Flowchart:

Flowchart: JavaScript Math- Get the highest number from three different numbers

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://www.w3resource.com/javascript-exercises/javascript-math-exercise-31.php