Question

In JavaScript, Define a function which takes a number as a parameter and if the number...

In JavaScript, Define a function which takes a number as a parameter and if the number is less than 0 or higher than 100, display the message, “the number is NOT a valid number”, otherwise display “the number is a valid number”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

//Function definition for checking the validity of the number
function parameterValid(number) {
   // If the number is less than 0 or higher than 100
   if(number < 0 || number > 100){
       // Print that it is not a valid number
       console.log("The number is NOT a valid number");
   }
   // Else
   else {
       // Print that it is a valid number
       console.log("The number is a valid number");
   }
}

// Calling the function with different parameters
parameterValid(-120)
parameterValid(42)
parameterValid(234)

Code Screenshot:

Sample Output:

Add a comment
Know the answer?
Add Answer to:
In JavaScript, Define a function which takes a number as a parameter and if the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT