Explore Functions
Explore Functions
Let's explore functions!
Explore:
- Write a function without an argument and use it.
- Write a function with arguments and use it.
// Here is a functionlet firstFunction = function () {console.log('First function! Ohhh, yeaaaah!');};// Here is how you call the function (ie. make it do something)firstFunction();firstFunction();firstFunction();// Here is a function that returns the string instead of logging it.let secondFunction = function () {return 'And a seeeecond function! Ohhh, yeaaaah!';};// To see it. We would print it here!console.log(secondFunction());// Here is a function that takes a single argumentlet thirdFunction = function (favFood) {return favFood + ' is your favorite food!';};console.log(thirdFunction('Pizza'));// Here is a function that takes two argumentslet fourthFunctioooon = function (city, country) {return 'You are from ' + city + ', ' + country;};console.log(fourthFunctioooon('USA', 'Earth'));// You can use any data type for an argument.// Note the function and argument names are variables.// You can choose the name.let differenceBetweenAandB = function (a, b) {return Math.abs(a - b);};console.log(differenceBetweenAandB(3, 273));