function-scope.js 568 B

1234567891011121314151617181920
  1. // Global scope (convertFahrenheitToCelsicius, tempOne, tempTwo)
  2. // Local scope (fahrenheit, celsius)
  3. // Local scope (isFreezing)
  4. let convertFahrenheitToCelsius = function(fahrenheit) {
  5. let celsius = (fahrenheit - 32) * (5/9)
  6. if (celsius <= 0) {
  7. let isFreezing = true
  8. }
  9. return celsius
  10. }
  11. // Call a couple of times (32 -> 0) (68 -> 20)
  12. let convertedTemp = convertFahrenheitToCelsius(32)
  13. let otherConvertedTemp = convertFahrenheitToCelsius(68)
  14. // Print the converted values
  15. console.log(convertedTemp)
  16. console.log(otherConvertedTemp)