JS exercise from my friends' 9th grade Computer Sci class

Instructions: A tipping calculator that asks for the bill total and your satisfaction rating then calculates the total cost. "Great" = 20% tip, "Good" = 15%, "Bad" = 0%

ex: Bill = $10, Satisfaction rating = Great, Tip = $2, Total = $12


Output:


My code:

<script>

  function start() {
    var tip;
    var total;
    var rate;

    // ask for bill
    var askBill = window.prompt('Bill (number only, no symbol)');
    if (askBill === null) {
      return;
    }

    // turn askBill string into number
    var bill = parseInt(askBill);
    if (isNaN(bill) == true) {
      bill = "null (Please enter a number)";
      rate = "null";
      tip = "null";
      total = "null";
    } else {

      // ask for satisfaction rating
      var askRate = window.prompt('Your satisfaction rating ("Great", "Good", or "Bad")')
      if (askRate === null) {
        return;
      }

      // rating
      rate = askRate.toUpperCase();
      switch (rate) {
        case "GREAT":
        tip = bill * 0.2;

        total;
        total = bill + tip;
        break;

        case "GOOD":
        tip = bill * 0.15;

        total;
        total = bill + tip;
        break;

        case "BAD":
        tip = 0;

        total;
        total = bill + tip;
        break;

       default:
        rate = 'null (Please choose either "good", "great", or "bad")';
        tip = "null";
        total = "null";
      }
  } //end of else

  // print
  document.getElementById('demo').innerHTML = 
  "<b>Bill</b>: " + bill + "<br><b>Satisfaction rating</b>: " + rate + 
  "<br><br><b>Tip</b>: " + tip + "<br><b>Total</b>: " + total;
  }
</script>


Author's notes:

lol! That was fun~ It seems my friends had a hard time with it. They told me they hated Javascript!