From 6c533012c29f5ad00a9eade1a2480541d5037af1 Mon Sep 17 00:00:00 2001 From: OyindamolaWbCode Date: Mon, 17 Apr 2023 02:23:21 +0200 Subject: [PATCH 1/2] intro to array --- functions/sum/exercise/script.js | 42 ++++++++++++++++++++++++++------ functions/sum/solution/script.js | 2 +- yourPlayground.js | 24 ++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/functions/sum/exercise/script.js b/functions/sum/exercise/script.js index 69d6b48..5c4b6c3 100644 --- a/functions/sum/exercise/script.js +++ b/functions/sum/exercise/script.js @@ -8,23 +8,49 @@ ES6 Syntax (Arrow function): const add = () => {} */ -function add(){ - //Add function here + +// function add(a, b){ +// //Add function here +// return a + b +// } + + +// let result1 = add(6, 7) +// console.log(result1) + +const sum = (a, b) =>{ +return a + b } +// console.log(sum(10, 50)) + -function sub(){ +function sub(a , b){ //Subtract function here + return a - b } +let result2 = sub(7, 6) +// console.log(result2) -function div(){ +function div(a,b){ //Divide function here + return(a / b) } +let result3 = div(20 , 2) +// console.log(result3) + +// function mul(a ,b){ +// //Multiply function here +// return(a * b) +// } +// let result4 = mul(20 , 2) +// console.log(result4) -function mul(){ - //Multiply function here -} console.log('hello from the SUM exercise') /* TODO: create a function that console logs the result of any of the above operations. -*/ \ No newline at end of file +*/ + + + + diff --git a/functions/sum/solution/script.js b/functions/sum/solution/script.js index 6a567a7..1593017 100644 --- a/functions/sum/solution/script.js +++ b/functions/sum/solution/script.js @@ -1 +1 @@ -console.log("Sum solution")) \ No newline at end of file +console.log("Sum solution") \ No newline at end of file diff --git a/yourPlayground.js b/yourPlayground.js index e69de29..795b457 100644 --- a/yourPlayground.js +++ b/yourPlayground.js @@ -0,0 +1,24 @@ +console.log('hello world') + +// Math Methods +//Floor ()- Rounds down +//Ceil() - Rounds up +//random() - Gives a random number + +let number = Math.floor(Math.random() * 4) + +console.log(number) + +const groceries = ['banana', 'orange', 'cucumber', 'kiwi', 'pear'] + +groceries.push('cookies') +groceries.push('chocolate') +console.log(groceries.indexOf('pear')) + console.log(groceries) + console.log(groceries[0]) + + //array slice +//start from 0 INCLUSIVE and up to 3 [0,3] + console.log(groceries.slice(0, 3)) +// console.log(groceries.splice(3, 6)) + console.log(groceries.splice(1, 3)) \ No newline at end of file From cf80f87a17b0db471d99bce384e540548d85baad Mon Sep 17 00:00:00 2001 From: OyindamolaWbCode Date: Mon, 17 Apr 2023 03:34:05 +0200 Subject: [PATCH 2/2] object js --- yourPlayground.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/yourPlayground.js b/yourPlayground.js index 795b457..9120b06 100644 --- a/yourPlayground.js +++ b/yourPlayground.js @@ -1,4 +1,3 @@ -console.log('hello world') // Math Methods //Floor ()- Rounds down @@ -21,4 +20,32 @@ console.log(groceries.indexOf('pear')) //start from 0 INCLUSIVE and up to 3 [0,3] console.log(groceries.slice(0, 3)) // console.log(groceries.splice(3, 6)) - console.log(groceries.splice(1, 3)) \ No newline at end of file + console.log(groceries.splice(1, 3)) + +// Objects + +const personal = { + name: 'Lampard', + shirt: "black" +} + +console.log(personal.name) + + + +const introducerMe = (name, shirt) => { + const person = { + name: name, + shirt: shirt, + assets: 5000000, + liabilty : 100000, + netWorth : function (){ + return this.assets - this.liabilty + } +} + const intro = `Hi, my name is ${person.name} and the color of my shirt is ${person.shirt} and my net worth is $ ${person.netWorth()} USD` + + return intro +} + +console.log(introducerMe('Oyindamola', 'flowery')) \ No newline at end of file