w3resource

JavaScript: Check whether three given integer values are in the range 50..99

JavaScript Basic: Exercise-29 with Solution

Write a JavaScript program to check whether three given integer values are in the range 50..99 (inclusive). Return true if one or more of them are in the specified range.

Pictorial Presentation:

JavaScript: Check whether three given integer values are in the range 50..99

Sample Solution:

JavaScript Code:

// Define a function named check_three_nums that takes three parameters x, y, and z
function check_three_nums(x, y, z) {
  // Check if at least one of the numbers is in the range between 50 and 99 (inclusive)
  return (x >= 50 && x <= 99) || (y >= 50 && y <= 99) || (z >= 50 && z <= 99);
}

// Log the result of calling the check_three_nums function with the arguments 50, 90, and 99 to the console
console.log(check_three_nums(50, 90, 99));

// Log the result of calling the check_three_nums function with the arguments 5, 9, and 199 to the console
console.log(check_three_nums(5, 9, 199));

// Log the result of calling the check_three_nums function with the arguments 65, 89, and 199 to the console
console.log(check_three_nums(65, 89, 199));

// Log the result of calling the check_three_nums function with the arguments 65, 9, and 199 to the console
console.log(check_three_nums(65, 9, 199)); 

Sample Output:

true
false
true
true

Live Demo:

See the Pen JavaScript: check if three given integer values are in a range-basic- ex-29 by w3resource (@w3resource) on CodePen.


Flowchart:

Flowchart: JavaScript - Check whether three given integer values are in the range 50..99

ES6 Version:

// Define a function named check_three_nums using arrow function syntax, which takes three parameters x, y, and z
const check_three_nums = (x, y, z) => (x >= 50 && x <= 99) || (y >= 50 && y <= 99) || (z >= 50 && z <= 99);

// Log the result of calling the check_three_nums function with the arguments 50, 90, and 99 to the console
console.log(check_three_nums(50, 90, 99));

// Log the result of calling the check_three_nums function with the arguments 5, 9, and 199 to the console
console.log(check_three_nums(5, 9, 199));

// Log the result of calling the check_three_nums function with the arguments 65, 89, and 199 to the console
console.log(check_three_nums(65, 89, 199));

// Log the result of calling the check_three_nums function with the arguments 65, 9, and 199 to the console
console.log(check_three_nums(65, 9, 199));

Previous: JavaScript program to check if two given integer values are in the range 50..99
Next: JavaScript program to check if a string "Script" presents at 5th (index 4) position in a given string,

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.