w3resource

JavaScript: Check whether three given numbers are increasing in strict mode or in soft mode

JavaScript Basic: Exercise-42 with Solution

Write a JavaScript program to check whether three given numbers are increasing in strict or in soft mode.
Note: Strict mode -> 10, 15, 31 : Soft mode -> 24, 22, 31 or 22, 22, 31

Sample Solution:

JavaScript Code:

// Define a function named number_order with parameters x, y, and z
function number_order(x, y, z) {
  // Check if y is greater than x and z is greater than y
  if (y > x && z > y) {
    return "strict mode";    
  } 
  // Check if z is greater than y
  else if (z > y) {
    return "Soft mode";
  } 
  // If none of the conditions are met, return "Undefined"
  else {
    return "Undefined";
  }
}

// Log the result of calling number_order with the arguments 10, 15, and 31 to the console
console.log(number_order(10, 15, 31));

// Log the result of calling number_order with the arguments 24, 22, and 31 to the console
console.log(number_order(24, 22, 31));

// Log the result of calling number_order with the arguments 50, 21, and 15 to the console
console.log(number_order(50, 21, 15)); 

Output:

strict mode
Soft mode
Undefinded

Live Demo:

See the Pen JavaScript: Check whether three given numbers are increasing in strict mode - basic-ex-42 by w3resource (@w3resource) on CodePen.


Flowchart:

Flowchart: JavaScript - Check whether three given numbers are increasing in strict mode or in soft mode

ES6 Version:

// Define a function named number_order using arrow function syntax with parameters x, y, and z
const number_order = (x, y, z) => {
  // Check if y is greater than x and z is greater than y
  if (y > x && z > y) {
    return "strict mode";
  } else if (z > y) {
    // Check if z is greater than y
    return "Soft mode";
  } else {
    // Return "Undefined" if none of the conditions are met
    return "Undefined";
  }
};

// Log the result of calling number_order with the arguments 10, 15, and 31 to the console
console.log(number_order(10, 15, 31));

// Log the result of calling number_order with the arguments 24, 22, and 31 to the console
console.log(number_order(24, 22, 31));

// Log the result of calling number_order with the arguments 50, 21, and 15 to the console
console.log(number_order(50, 21, 15)); 

Improve this sample solution and post your code through Disqus.

Previous: JavaScript program to check three given numbers, if the three numbers are same return 30 otherwise return 20 and if two numbers are same return 40.
Next: JavaScript program to check from three given numbers (non negative integers) that two or all of them have the same rightmost digit.

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.