function pt 2

PHOTO EMBED

Wed Jun 22 2022 20:35:07 GMT+0000 (Coordinated Universal Time)

Saved by @cruz #javascript

function hello(name) {
   return `Hello, ${name}!`;
}

console.log(hello("Lamar"));

//In this example, name is a parameter. It is part of the function definition, and behaves like a variable that exists only within the function.The value "Lamar" that is used when we invoke the function on line 5 is an argument. It is a specific value that is used during the function call.The difference between a parameter and an argument is the same as that between a variable and a value. A variable refers to a specific value, just like a parameter refers to a specific argument when a function is called. Like a value, an argument is a concrete piece of data.

function hello(name = "World") {
   return `Hello, ${name}!`;
}

console.log(hello());
console.log(hello("Lamar"));
//this example modifies the hello function to use a default value for name. If name is not defined when hello is called, it will use the default value.

function monitorCount(rows, columns) {
  return rows * columns;
}

const numOfMonitors = monitorCount(5, 4);

console.log(numOfMonitors);


// examples below of "helper functions" when a functions uses info from a different function

function monitorCount(rows, columns) {
  return rows * columns;
}

function costOfMonitors(rows, columns){
  return monitorCount(rows, columns) *200;
}

const totalCost = costOfMonitors(5,4);

console.log(totalCost);

//Function expressions
const plantNeedsWater = function(day) {
  if(day === 'Wednesday'){
    return true;
  }
  else{
    return false;
  }
}

console.log(plantNeedsWater("Tuesday"));

content_copyCOPY