0

var total = 0;
        var entrycount = 0
        var entry;
        do {
            entry = prompt("Enter number grade from 0 through 100\n" +
            "Or enter 999 to end entries", 999);
            entry = parseInt (entry);
            if (entry >= 0 && entry >= 59) {
                alert("Number grade=  " + entry + '\n' +
                "Letter grade = A"
                );
        
            }

I'm working on a javascript project for school. I need to create a program that prompts the user to enter a number grade and displays that number grade with the corresponding letter grade. I couldn't get it to work because it just skips past the javascript and displays the h1. When I was troubleshooting it I noticed that my variable entry is not highlighted blue as a variable in the alert statement. I don't know if this is the main problem but I can't figure out how to fix it anyway.

<!DOCTYPE html> 
   <html> 
      <head> 
         <meta charset="utf-8"> 
            <title>Show letter grade</title> 
<script> 
   var total = 0; 
   var entrycount = 0; var entry; 
   
      entry = prompt("Enter number grade from 0 through 100\n" + "Or enter 999 to end entries", 999);
      entry = parseInt (entry); 
         if (entry >= 0 && entry <= 59) { 
             alert ("Number grade = + entry\n" + "Letter grade = F") } 
   
</script> 
      </head> 
      <body> 
         <main> 
            <h1>This page is displayed after the JavaScript is executed</h1> 
         </main> 
      </body> 
   </html>
  • Show letter grade

    This page is displayed after the JavaScript is executed

    – Alexander's Workshop Jul 14 '20 at 21:52
  • 1
    Please post your code as text, not an image. – Barmar Jul 14 '20 at 21:52
  • 1
    Put the code in the question. You can use a [Stack Snippet](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) to make it executable. – Barmar Jul 14 '20 at 21:53
  • 2
    You have a syntax error. it should be: `if (entry >= 0 && entry <= 59)` – Barmar Jul 14 '20 at 21:54
  • 2
    Don't you see the squiggles under `<=`. That's your editor telling you that it's bad code. – Barmar Jul 14 '20 at 21:55
  • Thanks for the heads up on the syntax error. I fixed that but the alert stayed the same and the browser is still ignoring the javascript – Alexander's Workshop Jul 14 '20 at 22:01
  • Missing quotes? `alert("Number grade = " + entry + "\nLetter grade = F")` – freedomn-m Jul 14 '20 at 22:09
  • @Alexander'sWorkshop You should check your browser console, it will tell you that there are syntax errors, and you can click on the line number and it will show you exactly where it is. – Barmar Jul 14 '20 at 22:14
  • @Barmar the consol does through a syntax error unexpected token '<=' – Alexander's Workshop Jul 14 '20 at 22:20
  • Fixed the variable problem but the browser is still skipping the code and going straight to h1 – Alexander's Workshop Jul 14 '20 at 22:24
  • When I run the snippet in the question and enter `40`, I get the second alert. – Barmar Jul 14 '20 at 22:37
  • I figured it all out. I was running a do while loop when I should have been running a while loop. Thanks for the help – Alexander's Workshop Jul 14 '20 at 23:38

0 Answers0