Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JavaScript Program to Display Prime Numbers Between Two Intervals Using Functions
Next article icon

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 ?

How to display a message when given number is between the range using JavaScript ?



Next Article
JavaScript Program to Display Prime Numbers Between Two Intervals Using Functions

K

KapilChhipa
Improve
Article Tags :
  • HTML
  • JavaScript
  • Web Technologies
  • JavaScript-Methods
  • JavaScript-Numbers
  • JavaScript-Questions

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
  • How to check a number is even without using modulo operator in JavaScript ?
    In this article, we learn how to check if a number is even without using the % or modulo operator. The methods are mentioned below. 1. By using the bitwise '&' operator: When & operation is done on a number with 1 it will return 0 if the number is zero. We will use this method to check if th
    3 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 Convert a Float Number to the Whole Number in JavaScript?
    Given a float number and the task is to convert a float number to a whole number using JavaScript. Below are various methods to convert float numbers to whole numbers in JavaScript: Table of Content Math.floor (floating argument)Math.ceil (floating argument) Math.round (floating argument)Math.trunc
    4 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 Content By using ASCII ValueBy using replace(), isNan() functionBy using ASCII ValueIn this approach, we are going to
    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
  • How to get decimal portion of a number using JavaScript ?
    Given a float number, The task is to separate the number into integer and decimal parts using JavaScript. For example, a value of 15.6 would be split into two numbers, i.e. 15 and 0.6 Here are a few methods discussed. These are the following methods: Table of Content Javascript String split() Method
    3 min read
  • Generate Random Number in Given Range Using JavaScript
    Here are the different ways to generate random numbers in a given range using JavaScript 1. Using Math.random(): basic ApproachThis is the simplest way to generate a random number within a range using Math.random(). [GFGTABS] JavaScript let min = 10; let max = 20; let random = Math.floor(Math.random
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences