Question

In: Computer Science

needing assistance with writing an HTML doc with JavaScript. Making and Age range calculator -two independent...

needing assistance with writing an HTML doc with JavaScript.


Making and Age range calculator

-two independent buttons on the screen. Each button will ask them for their age.

A teenager is someone who is ages 13 to 19. Someone who is younger or older than this age range is not a teenager.

•The first button will check to see if someone is a teenager. This should use a logical AND operator.

•The secons button will check to see if someone is NOT a teenager. This should use a logical OR operator.

Solutions

Expert Solution

HTML & Javascript Code:

<html>
  
   <head>
       <script type="text/javascript">
          
           //Function that checks for teenager
           function checkTeenager()
           {
               //Reading age from user
               var age = parseInt(prompt("Please enter your age: ", "0"));
              
               //Checking age
               if(age>=13 && age<=19)
               {
                   alert("You are a teenager");
               }
               else
               {
                   alert("You are not a teenager");
               }
           }
          
           //Function that checks for not a teenager
           function checkNotTeenager()
           {
               //Reading age from user
               var age = parseInt(prompt("Please enter your age: ", "0"));
              
               //Checking age
               if(age<13 || age>19)
               {
                   alert("You are not a teenager");
               }
               else
               {
                   alert("You are a teenager");
               }
           }
          
       </script>
   </head>
  
   <body>
       <input type="button" value="Check for Teenager" onclick="checkTeenager()">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
       <input type="button" value="Check for Not a Teenager" onclick="checkNotTeenager()">
   </body>

</html>

__________________________________________________________________________________________

Sample Run:


Related Solutions

JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I edit the JavaScript below so that when the calculate button is clicked the total price only shows two decimal places by using the toFixed() method? ----------------------------------------------------------------------------------------------------------- JavaScript: // Variables var tax = "tax"; // Tax percentage var taxRate = document.getElementById('tax'); // Selecting tax element // On the time of loading the DOM we are setting the tax rate window.addEventListener('DOMContentLoaded', (event) => { taxRate.value =...
I need assistance in making a simple html and php script that lets a user explor...
I need assistance in making a simple html and php script that lets a user explor the RGB color specturum. It should be able to use 6 buttons (R+,G+,B+,R-,G-,B-) that when pressed, add or subtract 2 points (ranging from 0-255) of that color from the RGB ratio. The new RGB color is then displayed in a small window/box at the bottom of the page for the user to see. This should allow the user to explore all the different colors...
Perform one correlation between two independent variables, such as Age and Relationship with Coworkers. Perform the...
Perform one correlation between two independent variables, such as Age and Relationship with Coworkers. Perform the second correlation on an independent variable (such as Relationship with Direct Supervisor) and the dependent variable (such as Workplace Happiness Rating. Gender Age Supervisor Telecommute Coworkers Happiness Engagement Overall Rating 1 29 1 1 2 7 8 15 2 32 4 1 3 9 10 19 1 39 1 1 1 4 5 8 1 25 2 1 2 5 8 13 1 27...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT