Variable Scope

If I run this code with isThePrice2 function, nothing after the alert(warning) is encountered in the function will print out.
I only get alerts for 4 and 5. Then NOTHING! If I take out isThePrice2 function, then isThePrice3 function will output. Does the out of scope in isThePrice2 screw up the program somehow?

Thanks.

<!doctype html>

<head>

    <meta charset="utf-8">

    <title>Scope</title>

    <style>

       

    </style>

</head>
<script>

   function isThePriceRight(cost) {

       let total=cost++;

       if (total > 3) {

           alert(total);

       } else {

           alert("not enough");

       }

   }

   isThePriceRight(4);

   // this function screws up the output of everything after alert(warning)

   function isThePriceRight2(cost) {

       let total=cost++;

       if(total>3) {

           let warning=true;

           alert(total);

       } else {

           alert("not enough 2");

       }

       alert(warning);

   }

   isThePriceRight2(5);

   // this function will not output an alert unless I remove the function isThePriceRight2
   function isThePriceRight3(cost) {

       let total=cost++;

       if(total>3) {

           var warning=true;

           alert(total);

       } else {

           alert("not enough 2");

       }
       
       alert(warning);

   }

   isThePriceRight3(6);

   alert("HELP!!! This is never output");

</script>

Usually when something like that happens it’s because of an error. Check the JavaScript console for errors to see what went wrong. I’ll give you a hint: warning

1 Like

Ya got it. Thanks. Didn’t realize that stops the whole program.
Got more info as well on bottom of page 91.