From 599bb5a99acf971254dfe786af93517150d0b1cb Mon Sep 17 00:00:00 2001 From: Parth Adokar Date: Fri, 5 May 2023 19:43:40 +0530 Subject: [PATCH] day-1 --- functions/sum/exercise/script.js | 26 ++++---- yourPlayground.js | 107 +++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 12 deletions(-) diff --git a/functions/sum/exercise/script.js b/functions/sum/exercise/script.js index 69d6b48..aaef0b7 100644 --- a/functions/sum/exercise/script.js +++ b/functions/sum/exercise/script.js @@ -7,22 +7,24 @@ ES5 Syntax: function Add(){} ES6 Syntax (Arrow function): const add = () => {} */ +// Addition function here -function add(){ - //Add function here -} +const add = (a,b) => a+b -function sub(){ - //Subtract function here -} +console.log(add(10,20)); -function div(){ - //Divide function here -} +//Subtract function here +const sub = (a,b) => a-b +console.log(sub(20,10)); -function mul(){ - //Multiply function here -} +//Divide function here +const div = (a,b) => a/b +console.log(div(5,10)); + +//Multiply function here + +const mul = (a,b) => a*b +console.log(mul(5,10)); console.log('hello from the SUM exercise') /* diff --git a/yourPlayground.js b/yourPlayground.js index e69de29..09d203b 100644 --- a/yourPlayground.js +++ b/yourPlayground.js @@ -0,0 +1,107 @@ +// console.log('Hello World') +// console.log('Parth') + +// // variables +// let name = 'Parth Adokar' +// console.log(name) + +// let sentence = 'How are you doing , Hope you are doing great' +// console.log(sentence) + +// operators +// food = Number(prompt('What is your final bill amount')) +// tipPercentage = Number(prompt('How much do you want to tip?')) / 100 +// tipAmount = food * tipPercentage +// total = food + tipAmount +// console.log('total',total) +// console.log('tip amount',tipAmount) + +// user input + +// data types + +// type casting + +// Weather app + +// let weather = prompt("How is the weather?") +// if (weather == 'rain') { +// console.log('Grab your umbrella ✔') +// } else { +// console.log('Wear your sunglasses ✌') +// } + +// functions +// this is a function called 'sayMyName' +// this has zero arguements +// this logs out the name to the console +function sayMyName(){ + console.log('Parth'); +} + +// sayMyName() + +// this function is called 'sayMyName2' +// this has one arguments +// this also logs out name to console +function sayMyName2(name){ + console.log(name); +} + +// sayMyName2('Parth') + +// this function is called 'greeting' +// this takes one argument called 'name' +// this prints out a sentence in a template literal +function greeting (name) { + greet = `Hi ${name}, Nice to meet you!` + console.log(greet); +} + +// greeting('Parth') + +function sum(a,b) { + return a + b +} + +num1 = sum(2,3) +// console.log(num1); + +function calculateFoodTotal(food,tip){ + tipPercentage = tip / 100 + tipAmount = food * tipPercentage + total = sum(food,tipAmount) + return total +} + +// console.log(calculateFoodTotal(200,20)); + +// Arrow Function +// arrow function with explicit return +const sum1 = (a,b) => { + return a + b; +} + +// Implicit Return +// IMP : arrow functions with implicit return , remove curly braces +const sumArrow5 = (a,b) => a + b + +// console.log(sumArrow5(10,30)); + +// Array +// Created a array +// Used indexing +item = ['🍎','🍊','🍌'] +// console.log(item) +// console.log(item[2]) +// Pushed a item in the array +item.push('🍫') +// console.log(item) + +// Array slice +// Starts from 0 and upto to 2 [0,1] +// console.log(item.slice(0,2)) + +// console.log(item.indexOf('🍫')); + +// console.log(item.length); \ No newline at end of file