How to display a message when given number is between the range using JavaScript ? Last Updated : 15 Feb, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn to display a message when a number is between the given range using JavaScript. We take a number from the user and tell the user whether it is in between a range or not, in our case, the range is 1 to 10. Approach: We create a button and add a click event listener to it. When we click on button, a prompt is shown on the browser screen using the JavaScript prompt() function asking for input. The variable is checked if it's in between the range or not by using the JavaScript if-else statement. If this input is in between the range, we show a success message on the screen using the innerHTML property otherwise, we show a failure message. Example: HTML <div> <h1 style="color:green">GeeksforGeeks</h1> <button onclick="fun()"> click me </button> <p id="gfg2"></p> </div> <script> function fun() { const input = prompt('Please enter a number:'); if (input >= 1 && input <= 10) document.getElementById("gfg2") .innerHTML = input + " Success!"; else document.getElementById("gfg2") .innerHTML = input + " Fail!" } </script> Output: How to display a message when given number is between the range using JavaScript ? Comment More infoAdvertise with us Next Article How to display a message when given number is between the range using JavaScript ? K KapilChhipa Follow Improve Article Tags : JavaScript Web Technologies HTML JavaScript-Numbers JavaScript-Methods JavaScript-Questions +2 More Similar Reads How to Print a Message to the Error Console Using JavaScript ? This article will show you how to print a message using JavaScript on the error console. There are three methods to display the error console, these are: Table of Content Using console.error() MethodUsing console.warn() MethodUsing console.info() MethodApproach 1: Using console.error() MethodThe con 2 min read JavaScript Program to Display Prime Numbers Between Two Intervals Using Functions Prime numbers are natural numbers greater than 1 that are only divisible by 1 and themselves. In this article, we will explore how to create a JavaScript program to display all prime numbers between two given intervals using functions. Approach 1: Using Basic Loop and FunctionThe most straightforwar 2 min read JavaScript Program to Display Armstrong Number Between Two Intervals An Armstrong number is a number that is equal to the sum of its digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. In this article, we'll explore how to create a JavaScript program to display all Armstrong numbers within a 2 min read How to force Input field to enter numbers only using JavaScript ? We are going to learn how can we force the Input field to enter numbers only using JavaScript. Below are the approaches to force input field force numbers using JavaScript:Table of ContentBy using ASCII ValueBy using replace(), isNan() functionBy using ASCII ValueIn this approach, we are going to us 3 min read How to create a Number object using JavaScript ? In this article, we will discuss how to create a Number object using JavaScript. A number object is used to represent integers, decimal or float point numbers, and many more. The primitive wrapper object Number is used to represent and handle numbers. examples: 20, 0.25. We generally don't need to w 2 min read How to generate a n-digit number using JavaScript? The task is to generate an n-Digit random number with the help of JavaScript. You can also generate random numbers in the given range using JavaScript. Below are the approaches to generate a n-digit number using JavaScript: Table of Content Using Math.random()Math.random() Method and .substring() Me 2 min read Generate Random Number in Given Range Using JavaScript Here are the different ways to generate random numbers in a given range using JavaScript1. Using Math.random(): basic ApproachThis is the simplest way to generate a random number within a range using Math.random().JavaScriptlet min = 10; let max = 20; let random = Math.floor(Math.random() * (max - m 3 min read How to check whether a number is NaN or finite in JavaScript ? When working with numbers in JavaScript, it's important to know how to determine if a value is NaN (Not-a-Number) or finite. This knowledge is crucial for data validation, error handling, and ensuring your code behaves as expected. In this article, we will see how to check whether the number is NaN 3 min read How to limit a number between a min/max value in JavaScript ? We can limit a number between a min/max value using the is-else condition and using the Math.min and Math.max methods of JavaScript.Below are the approaches to limit a number between a min/max value in JavaScript:Table of ContentUsing the if-else conditionUsing the Math.min() and Math.max() methodsU 2 min read JavaScript Program to Check whether the Input Number is a Neon Number A neon number is a number where the sum of digits of its square equals the number itself. For example, 9 is a neon number because 9^2 = 81, and the sum of the digits 81 is 9. There are several ways to check if a given number is a neon number in JavaScript or not which are as follows: Table of Conten 2 min read Like