Skip to content

Commit

Permalink
new js functions
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyMatthee committed Sep 21, 2022
1 parent f5ab95d commit 4b3e274
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions even.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const isEven = function (num) {
return num % 2 === 0;
}

const tenIsEven = isEven(10);
const elevenIsEven = isEven(11);

console.log(tenIsEven);
console.log(elevenIsEven);

/*We can simplify the above code using them directly,
instead of setting to them to new variables!*/

const isNewEven = function (num) { //Renaming varialble to avoid syntax error!
return num % 2 === 0;
}

console.log(isNewEven(10));
console.log(isNewEven(11));
15 changes: 15 additions & 0 deletions hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const sayHello = function (name) { // Create a function with a parameter "Name"
console.log("Hello, " + name); //Log the string within the function
}

sayHello("Wes"); //Delcare the function with a set parameter
sayHello("Lina");//Again
sayHello("Elmtree");//and again!!

//This is how you return a parameter to a variable the log it to the console.
const returnSayHello = function (name) { // create a function
return "Hello, " + name; // return a conditon
}

const greeting = returnSayHello("Peter"); // Create a variable to hold the function return
console.log(greeting); // log the variable

0 comments on commit 4b3e274

Please sign in to comment.