Problem with Minimum exercise

Continuing the discussion from Chapter 3 Exercises:

So for some reason my minimum function is not alerting the user. Can someone give me a heads up on what is wrong with my code. I think it has something to do with how I ordered the returns and console.log, but then again I am not completely sure. Thanks in advance!!!

<script> 

      //Minimum Exercise

      function minimum(a,b){
        if(a<b){
          let result = a 
        }
        else{
          let result = b
        }
        return result
      }

    var Min436 = (minimum(36,4))

    alert(Min436)

    
    </script>

1 Like

Please remove the extra parenthesis.

It should be -
var Min436 = minimum(36,4)

Hope this helps. :slight_smile:

Thanks Malik!!

Unfortunately the code still fails to alert the minimum when I copy paste it into the console. Do you think there are any other problems with the code?

I have a feeling I may have miss placed a “return”, or incorrectly assigned a the result variable.

Thanks for your help as always!

Oh that’s because you used “let” to define your variables. “let” is bracket scoped so the variable isn’t accessible outside the brackets.

Best would be to do this –

<script> 

      //Minimum Exercise

      function minimum(a,b){
       let result = a; 
        if(a<b){
          result = a 
        }
        else{
          result = b
        }
        return result
      }

    var Min436 = minimum(36,4)

    alert(Min436)

    
    </script>

This should work

1 Like