This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hey guys, I'm pretty new to JavaScript and I'm trying to build a program that converts a number grade to a letter grade. When I go and try to run the code and enter a number such as '75', I get the output 'F' and this goes for every number '85', '90' etc, I still get the output 'F'. Could someone please help me try to understand where I went wrong? Thanks.
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8" />
<title>Grade Converter</title>
</head>
<body>
<h3>Grade</h3>
<input type="text" id="numGrade" />
<button onclick="convert()">Convert</button>
<br></br>
Grade:<span id="letterGrade"></span>
<script src = "example1.js">
</script>
</body>
</html>
let num = document.getElementById('numGrade').value;
function convert(){
  let numeric = parseInt(num);
  let letterGrade = '';
  if(num >= 90 && num <= 100)
  {
    letterGrade = "A ";
  }
  else if(num >= 80 && num <= 89)
  {
    letterGrade = "A";
  }
  else if(num >= 75 && num <= 79)
  {
    letterGrade = "B ";
  }
  else if(num >= 70 && num <= 74)
  {
    letterGrade = "B";
  }
  else if(num >= 65 && num <= 69)
  {
    letterGrade = "C ";
  }
  else if(num >= 60 && num <= 64)
  {
    letterGrade = "C";
  }
  else if(num >= 55 && num <= 59)
  {
    letterGrade = "D ";
  }
  else if(num >= 50 && num <= 54)
  {
    letterGrade = "D";
  }
  else if(num >= 48 && num <= 49)
  {
    letterGrade = "E";
  }
  else if (num >= 0 && num <= 47)
  {
    letterGrade = "F";
  }
  else
  {
    letterGrade = "You entered the wrong grade.";
  }
  document.getElementById("letterGrade").innerHTML=letterGrade;
 Â
}
Subreddit
Post Details
- Posted
- 6 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...