functions-101.js 731 B

12345678910111213141516171819202122232425262728293031323334
  1. // Function - input (argument), code, output (return value)
  2. let greetUser = function () {
  3. console.log('Welcome user!')
  4. }
  5. greetUser()
  6. let square = function (num) {
  7. let result = num * num
  8. return result
  9. }
  10. let value = square(3)
  11. let otherValue = square(10)
  12. console.log(value)
  13. console.log(otherValue)
  14. // Challenge Area
  15. // convertFahrenheitToCelsius
  16. let convertFahrenheitToCelsius = function(fahrenheit) {
  17. let celsius = (fahrenheit - 32) * (5/9)
  18. return celsius
  19. }
  20. // Call a couple of times (32 -> 0) (68 -> 20)
  21. let convertedTemp = convertFahrenheitToCelsius(32)
  22. let otherConvertedTemp = convertFahrenheitToCelsius(68)
  23. // Print the converted values
  24. console.log(convertedTemp)
  25. console.log(otherConvertedTemp)