Question

Ask the user to enter a GPA. If the value they enter is empty, null, or...

Ask the user to enter a GPA.

If the value they enter is empty, null, or non-numeric(isNaN()), or is not between 0.0 and 4.0 (inclusive), prompt them again.

Continue to prompt them until they enter a valid GPA input.

My javascript code below is not working.

let gpa="";

do{


gpa =parseFloat(prompt("Please enter your gpa"));
console.log(gpa);

}while (gpa==null || gpa === " " ||isNaN(gpa) || gpa <=0.0 || gpa>4.0);
var apg=gpa.toFixed(1);
document.write(" <h1> your gpa is </h1>" + apg);

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

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Click me</button>


<script>
function myFunction() {
let gpa="";

do{


gpa =parseFloat(prompt("Please enter your gpa"));
console.log(gpa);

}while (gpa==null || gpa>4.0);
var apg=gpa.toFixed(1);
document.write(" <h1> your gpa is </h1>" + apg);

}
</script>

</body>
</html>

your gpa is 3.0

Add a comment
Know the answer?
Add Answer to:
Ask the user to enter a GPA. If the value they enter is empty, null, or...
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
  • Python: Printing Student Data Ask the user: "How many students are in the class?" Read in...

    Python: Printing Student Data Ask the user: "How many students are in the class?" Read in the number of students If there are students For each student Ask for the name of the student: "Enter the name of student:" Read in the name of the student If the student's name is greater than 24 characters Do not display this student's data Do not ask for their gpa Print: "Name of student cannot exceed 24 characters." Ask for the gpa of...

  • JAVASCRIPT HOMEWORK PLEASE HELP! ask the user to input their temperature. Use this information to determine...

    JAVASCRIPT HOMEWORK PLEASE HELP! ask the user to input their temperature. Use this information to determine if the person has a fever (above 98.6), hypothermia (below 95), or a normal temperature (98.6) If the user’s temperature is normal congratulate them on their health and end the program. If not, give the user advice on how to treat their condition. Continue checking the user’s temperature until they feel better. Find out if the user feels better. If so, end the program....

  • Write a Python program, with comments, to do the following:                        Ask the user to enter...

    Write a Python program, with comments, to do the following:                        Ask the user to enter a string with at least 7 characters. Assume user will enter a valid string. Assign the string to a variable str1 and print str1. In a loop do the following: Update the value of str1 so that the first character from the current value of str1 is removed and added to the end. Print the updated str1.       The loop should continue until updated...

  • Form for a user to enter billing and shipping information. A checkbox that when clicked copies...

    Form for a user to enter billing and shipping information. A checkbox that when clicked copies all of the billing information to the shipping information. A submit button that, when clicked, will make sure that all text fields have had data entered into them. Create your own validation in for the fields, No automatic browser validation. JavaScript/HTML <!DOCTYPE html> <html lang="en"> <head> </head> <body>    <div class="container">       <header>          <h1>                      </h1>       </header>       <nav>          <ul>...

  • Could I get some help with the following Task? The program should be implemented in JavaScript and running on Firefox, a web browser independent to operating systems. The client has specified the foll...

    Could I get some help with the following Task? The program should be implemented in JavaScript and running on Firefox, a web browser independent to operating systems. The client has specified the following requirements for the functionality of the program: 1. The program should be running without errors throughout two Phases: Information Gathering and Information Presenting. 2. Information Gathering is to gather the information such as state/territory name, the population and population change over previous year for calculation of APG;...

  • Java programming for ticket price calculator.  It should ask the user if they would like to process...

    Java programming for ticket price calculator.  It should ask the user if they would like to process another ticket order. They should indicate their selection with a Y or N. If they indicate yes, then it should repeat the entire program with the exception of the welcome screen. If they indicate no, it should show the final thank you message and end the program. If they indicate an invalid answer, it should display an error and re-prompt them for a Y...

  • MATLAB Part 1 – randFloatValue.m This function accepts two numbers, lower and upper, and returns a...

    MATLAB Part 1 – randFloatValue.m This function accepts two numbers, lower and upper, and returns a random number in between. The rand() function will be useful here. Part 2 – getValue.m getValue has three parameters: - prompt: A string that is displayed to the user. This should be passed to your input function. - lower: The lowest number that the user is allowed to input - upper: The highest number that the user is allowed to input This function should...

  • C Code Create a tool in which a user can enter a string (up to 25...

    C Code Create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the “quit” command. The commands are: • “Replace All” If a user types “replace all” using ANY sort of capitalization, your program will prompt the user to enter the character to change...

  • JAVASCRIPT Create a simple web page that contains a JavaScript form that will allow the user...

    JAVASCRIPT Create a simple web page that contains a JavaScript form that will allow the user to answer 7 trivia questions. Your trivia game should contain: 2 text boxes 2 select dropdowns 2 multiple choice questions (using radio buttons, 4 options min) 1 choose-all-that-apply (checkboxes, 4 options min, one answer should be "None of the above"). No part-points for semi-correct answers. The questions can cover any topic you wish - but please keep it professional and easy enough that the...

  • Develop an HTML form that could be used to enter your book information (Books, Authors, and...

    Develop an HTML form that could be used to enter your book information (Books, Authors, and Publishers) start with the HTML/JavaScript template provided Expand upon it! What field information would you enter into a system? Have your form use more then just character text fields ... radio buttons, pick lists, and other elements make your form easier to use and you don't need to do lots of JavaScript checks. What fields would be mandatory ... which could be left blank?...

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