Explore Functions

Explore Functions

Let's explore functions!

Explore:

  1. Write a function without an argument and use it.
  2. Write a function with arguments and use it.
// Here is a function
let 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 argument
let thirdFunction = function (favFood) {
return favFood + ' is your favorite food!';
};
console.log(thirdFunction('Pizza'));
// Here is a function that takes two arguments
let 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));