From 48b6e42084038aeb861d4e4e43575c7e9c40e649 Mon Sep 17 00:00:00 2001 From: Baraa Kolly Date: Thu, 2 Apr 2020 16:18:35 +0200 Subject: [PATCH] week3 --- .../homework/js-exercises/drinkList.js | 35 ++ .../homework/js-exercises/evenOddReporter.js | 7 + .../homework/js-exercises/gradeCalculato.js | 33 ++ .../homework/js-exercises/readingList.js | 17 + .../homework/js-exercises/recipeCard.js | 19 + .../homework/js-exercises/removeComma.js | 8 + .../report.20200328.160859.7540.0.001.json | 396 ++++++++++++++++++ .../js-exercises/CreditCardValidator.js | 79 ++++ .../js-exercises/addToShoppingCart.js | 14 + .../homework/js-exercises/calculateDogAge.js | 13 + .../js-exercises/calculateTotalPrice.js | 32 ++ Week3/homework/js-exercises/giveCompliment.js | 12 + Week3/homework/js-exercises/tellFortune.js | 28 ++ 13 files changed, 693 insertions(+) create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/drinkList.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/evenOddReporter.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/gradeCalculato.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/readingList.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/recipeCard.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/removeComma.js create mode 100644 Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/report.20200328.160859.7540.0.001.json create mode 100644 Week3/homework/js-exercises/CreditCardValidator.js create mode 100644 Week3/homework/js-exercises/addToShoppingCart.js create mode 100644 Week3/homework/js-exercises/calculateDogAge.js create mode 100644 Week3/homework/js-exercises/calculateTotalPrice.js create mode 100644 Week3/homework/js-exercises/giveCompliment.js create mode 100644 Week3/homework/js-exercises/tellFortune.js diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/drinkList.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/drinkList.js new file mode 100644 index 000000000..170de37cc --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/drinkList.js @@ -0,0 +1,35 @@ +"use strict"; +let drinkTray = []; + +const drinkTypes = ["cola", "lemonade", "water"]; +function myShuffle(array) { + for (var i = array.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var tmp = array[i]; + array[i] = array[j]; + array[j] = tmp; +} +return array; +} + +function fillTray(tray) { + let shuffleDrinkTypes = myShuffle(drinkTypes); + let drink; + let drinkObjList = []; + for( drink of shuffleDrinkTypes){ + let myObject = {name:drink , counter:0}; + drinkObjList.push(myObject); + + } + let i = 0; + for(drink of drinkObjList){ + while(i<5 && drink.counter<2) { + tray.push(drink.name); + drink.counter++; + i++; + } + } + + return tray; +} +console.log(`Hey guys, I brought a ${fillTray(drinkTray)}`); diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/evenOddReporter.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/evenOddReporter.js new file mode 100644 index 000000000..c3b29c270 --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/evenOddReporter.js @@ -0,0 +1,7 @@ +"use strict"; +for ( let i = 1; i <= 20 ; i++ ) { + if (i % 2 === 0){ + console.log(`The number ${i} is even!`) + } + else console.log(`The number ${i} is odd!`) +} \ No newline at end of file diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/gradeCalculato.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/gradeCalculato.js new file mode 100644 index 000000000..f6a200ade --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/gradeCalculato.js @@ -0,0 +1,33 @@ +"use strict"; + +let score; +const total; + +function gradeCalc (myScore,total) { + + //convert the score into a percentage + myScore = myScore/total *100; + + // check if the score is between 0..100 and if it's type is a number + if (typeof myScore !== 'number' || score <= 0 || score >= 100) + return "INVALID SCORE"; + + //calculate what grade corresponds with that percentage + let grade; + switch(true) { + case (myScore<50) : grade='F'; + break; + case (myScore<60 && myScore>=50) : grade='E'; + break; + case (myScore<70 && myScore>=60) : grade='D'; + break; + case (myScore<80 && myScore>=70) : grade='C'; + break; + case (myScore<90 && myScore>=80) : grade='B'; + break; + case (myScore<=90) : grade='A'; + break; + } + // return string contains a grade and the score + return `You got a ${grade} (${myScore}%)`; +} diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/readingList.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/readingList.js new file mode 100644 index 000000000..6cbe68154 --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/readingList.js @@ -0,0 +1,17 @@ +"use strict"; +//declare a variable that holds an array of 3 objects +let bookList = [ { title : "The Hunger Game" , author : "Suzanne Collins" , alreadyRead: false } , + { title : "The Da Vinci Code" , author : "Dan Brown" , alreadyRead: true } , + { title : "A Song Of Ice And Fire" , author : "George R.R. Martin" , alreadyRead: false }] +//log the book title and book author +let book; +for (book of bookList){ + console.log(`${book.title} by ${book.author}`); +} +//log the book depending on whether you read it yet or not +for (book of bookList) { + if( book.alreadyRead === true ) + console.log(`You already read ${book.title} by ${book.author} `); + else + console.log(`You still need to read ${book.title} by ${book.author} `); +} \ No newline at end of file diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/recipeCard.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/recipeCard.js new file mode 100644 index 000000000..430369f88 --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/recipeCard.js @@ -0,0 +1,19 @@ +"use strict"; +const recipe = { + title : "Falafel" , + servings : "3" , + ingredients : ['1 (15-oz.) can chickpeas, drained' , '4 cloves garlic, roughly chopped', + '1 shallot, roughly chopped' , '2 tbsp. freshly chopped parsley' , '1 tsp. ground cumin', + '1 tsp. ground coriander' , '3 tbsp. all-purpose flour' , 'Kosher salt' , + 'Freshly ground black pepper'] +} +function printRecipe (myRecipe) { +let ingredientList = ""; +let element; +for ( element of Object.values(myRecipe)[2] ) { + ingredientList += element+"\n"; +} +return ` Meal name: ${Object.values(recipe)[0]} \n Serves: ${Object.values(recipe)[1]} \n Ingredients: \n ${ingredientList}`; +} + +console.log(printRecipe(recipe)); \ No newline at end of file diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/removeComma.js b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/removeComma.js new file mode 100644 index 000000000..87c9254ce --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/removeComma.js @@ -0,0 +1,8 @@ +"use strict"; +let myString = "hello,this,is,a,difficult,to,read,sentence"; +console.log(myString.length); +let i; +for (i of myString){ + myString = myString.replace(/,/g," "); +} +console.log(myString); \ No newline at end of file diff --git a/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/report.20200328.160859.7540.0.001.json b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/report.20200328.160859.7540.0.001.json new file mode 100644 index 000000000..f34e65dc1 --- /dev/null +++ b/Week2/week-2-homework-BARAA KOLLY/homework/js-exercises/report.20200328.160859.7540.0.001.json @@ -0,0 +1,396 @@ + +{ + "header": { + "reportVersion": 1, + "event": "Allocation failed - JavaScript heap out of memory", + "trigger": "FatalError", + "filename": "report.20200328.160859.7540.0.001.json", + "dumpEventTime": "2020-03-28T16:09:00Z", + "dumpEventTimeStamp": "1585408140000", + "processId": 7540, + "cwd": "C:\\Users\\baraa\\desktop\\javaScript1\\week2\\homework\\js-exercises", + "commandLine": [ + "C:\\Program Files\\nodejs\\node.exe", + "drinkList.js" + ], + "nodejsVersion": "v12.16.1", + "wordSize": 64, + "arch": "x64", + "platform": "win32", + "componentVersions": { + "node": "12.16.1", + "v8": "7.8.279.23-node.31", + "uv": "1.34.0", + "zlib": "1.2.11", + "brotli": "1.0.7", + "ares": "1.15.0", + "modules": "72", + "nghttp2": "1.40.0", + "napi": "5", + "llhttp": "2.0.4", + "http_parser": "2.9.3", + "openssl": "1.1.1d", + "cldr": "35.1", + "icu": "64.2", + "tz": "2019c", + "unicode": "12.1" + }, + "release": { + "name": "node", + "lts": "Erbium", + "headersUrl": "https://nodejs.org/download/release/v12.16.1/node-v12.16.1-headers.tar.gz", + "sourceUrl": "https://nodejs.org/download/release/v12.16.1/node-v12.16.1.tar.gz", + "libUrl": "https://nodejs.org/download/release/v12.16.1/win-x64/node.lib" + }, + "osName": "Windows_NT", + "osRelease": "10.0.18362", + "osVersion": "Windows 10 Home", + "osMachine": "x86_64", + "cpus": [ + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 28196062, + "nice": 0, + "sys": 36757171, + "idle": 382938203, + "irq": 14039390 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 17060078, + "nice": 0, + "sys": 26733328, + "idle": 404097765, + "irq": 18806703 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 37828328, + "nice": 0, + "sys": 19423390, + "idle": 390639468, + "irq": 5185250 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 22911656, + "nice": 0, + "sys": 9653515, + "idle": 415326046, + "irq": 1870156 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 35167968, + "nice": 0, + "sys": 17372828, + "idle": 395350421, + "irq": 3910968 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 24013781, + "nice": 0, + "sys": 9335406, + "idle": 414542015, + "irq": 2039421 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 33781515, + "nice": 0, + "sys": 12526000, + "idle": 401583703, + "irq": 1920671 + }, + { + "model": "Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz", + "speed": 1498, + "user": 31892312, + "nice": 0, + "sys": 10377421, + "idle": 405621484, + "irq": 1129937 + } + ], + "networkInterfaces": [ + { + "name": "WiFi", + "internal": false, + "mac": "40:23:43:5b:77:9f", + "address": "fe80::b52d:3ad2:db59:db4", + "netmask": "ffff:ffff:ffff:ffff::", + "family": "IPv6", + "scopeid": 9 + }, + { + "name": "WiFi", + "internal": false, + "mac": "40:23:43:5b:77:9f", + "address": "192.168.0.135", + "netmask": "255.255.255.0", + "family": "IPv4" + }, + { + "name": "Loopback Pseudo-Interface 1", + "internal": true, + "mac": "00:00:00:00:00:00", + "address": "::1", + "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + "family": "IPv6", + "scopeid": 0 + }, + { + "name": "Loopback Pseudo-Interface 1", + "internal": true, + "mac": "00:00:00:00:00:00", + "address": "127.0.0.1", + "netmask": "255.0.0.0", + "family": "IPv4" + } + ], + "host": "LAPTOP-PNJ0RJE8" + }, + "javascriptStack": { + "message": "No stack.", + "stack": [ + "Unavailable." + ] + }, + "nativeStack": [ + { + "pc": "0x00007ff7308a19f9", + "symbol": "std::basic_ostream >::operator<<+10873" + }, + { + "pc": "0x00007ff7308a5e1c", + "symbol": "std::basic_ostream >::operator<<+28316" + }, + { + "pc": "0x00007ff7308a4dd8", + "symbol": "std::basic_ostream >::operator<<+24152" + }, + { + "pc": "0x00007ff7309a34cb", + "symbol": "v8::base::CPU::has_sse+38363" + }, + { + "pc": "0x00007ff7311b9f4e", + "symbol": "v8::Isolate::ReportExternalAllocationLimitReached+94" + }, + { + "pc": "0x00007ff7311a2021", + "symbol": "v8::SharedArrayBuffer::Externalize+833" + }, + { + "pc": "0x00007ff73106e57c", + "symbol": "v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436" + }, + { + "pc": "0x00007ff73108b47b", + "symbol": "v8::internal::Factory::NewFixedArrayWithFiller+59" + }, + { + "pc": "0x00007ff73108b431", + "symbol": "v8::internal::Factory::NewUninitializedFixedArray+65" + }, + { + "pc": "0x00007ff730f681ff", + "symbol": "v8::debug::Script::GetIsolate+7631" + }, + { + "pc": "0x00007ff730e1824a", + "symbol": "v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+162938" + }, + { + "pc": "0x00007ff731604ddd", + "symbol": "v8::internal::SetupIsolateDelegate::SetupHeap+546637" + }, + { + "pc": "0x00000357aea84169", + "symbol": "" + } + ], + "javascriptHeap": { + "totalMemory": 2730188800, + "totalCommittedMemory": 2730188800, + "usedMemory": 2695251824, + "availableMemory": 16759296, + "memoryLimit": 2197815296, + "heapSpaces": { + "read_only_space": { + "memorySize": 262144, + "committedMemory": 262144, + "capacity": 32808, + "used": 32808, + "available": 0 + }, + "new_space": { + "memorySize": 33554432, + "committedMemory": 33554432, + "capacity": 16759296, + "used": 0, + "available": 16759296 + }, + "old_space": { + "memorySize": 1982464, + "committedMemory": 1982464, + "capacity": 1269264, + "used": 1269264, + "available": 0 + }, + "code_space": { + "memorySize": 430080, + "committedMemory": 430080, + "capacity": 158304, + "used": 158304, + "available": 0 + }, + "map_space": { + "memorySize": 266240, + "committedMemory": 266240, + "capacity": 170560, + "used": 170560, + "available": 0 + }, + "large_object_space": { + "memorySize": 1791131648, + "committedMemory": 1791131648, + "capacity": 1791107224, + "used": 1791107224, + "available": 0 + }, + "code_large_object_space": { + "memorySize": 49152, + "committedMemory": 49152, + "capacity": 2784, + "used": 2784, + "available": 0 + }, + "new_large_object_space": { + "memorySize": 902512640, + "committedMemory": 902512640, + "capacity": 902510880, + "used": 902510880, + "available": 0 + } + } + }, + "resourceUsage": { + "userCpuSeconds": 2.609, + "kernelCpuSeconds": 2.109, + "cpuConsumptionPercent": 78.6333, + "maxRss": 1703616512, + "pageFaults": { + "IORequired": 766706, + "IONotRequired": 0 + }, + "fsActivity": { + "reads": 2, + "writes": 5 + } + }, + "libuv": [ + ], + "environmentVariables": { + "ALLUSERSPROFILE": "C:\\ProgramData", + "APPDATA": "C:\\Users\\baraa\\AppData\\Roaming", + "CommonProgramFiles": "C:\\Program Files\\Common Files", + "CommonProgramFiles(x86)": "C:\\Program Files (x86)\\Common Files", + "CommonProgramW6432": "C:\\Program Files\\Common Files", + "COMPUTERNAME": "LAPTOP-PNJ0RJE8", + "ComSpec": "C:\\windows\\system32\\cmd.exe", + "DriverData": "C:\\Windows\\System32\\Drivers\\DriverData", + "HOMEDRIVE": "C:", + "HOMEPATH": "\\Users\\baraa", + "LOCALAPPDATA": "C:\\Users\\baraa\\AppData\\Local", + "LOGONSERVER": "\\\\LAPTOP-PNJ0RJE8", + "nodejs": "C:\\Program Files\\nodejs", + "NUMBER_OF_PROCESSORS": "8", + "OneDrive": "C:\\Users\\baraa\\OneDrive", + "OneDriveConsumer": "C:\\Users\\baraa\\OneDrive", + "OnlineServices": "Online Services", + "OS": "Windows_NT", + "Path": "C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\windows\\System32\\OpenSSH\\;C:\\Program Files\\nodejs\\;C:\\Users\\baraa\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\baraa\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\baraa\\AppData\\Roaming\\npm", + "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL", + "platformcode": "KV", + "PROCESSOR_ARCHITECTURE": "AMD64", + "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 126 Stepping 5, GenuineIntel", + "PROCESSOR_LEVEL": "6", + "PROCESSOR_REVISION": "7e05", + "ProgramData": "C:\\ProgramData", + "ProgramFiles": "C:\\Program Files", + "ProgramFiles(x86)": "C:\\Program Files (x86)", + "ProgramW6432": "C:\\Program Files", + "PSModulePath": "C:\\Users\\baraa\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\windows\\system32\\WindowsPowerShell\\v1.0\\Modules", + "PUBLIC": "C:\\Users\\Public", + "RegionCode": "EMEA", + "SESSIONNAME": "Console", + "SystemDrive": "C:", + "SystemRoot": "C:\\windows", + "TEMP": "C:\\Users\\baraa\\AppData\\Local\\Temp", + "TMP": "C:\\Users\\baraa\\AppData\\Local\\Temp", + "USERDOMAIN": "LAPTOP-PNJ0RJE8", + "USERDOMAIN_ROAMINGPROFILE": "LAPTOP-PNJ0RJE8", + "USERNAME": "baraa", + "USERPROFILE": "C:\\Users\\baraa", + "windir": "C:\\windows", + "TERM_PROGRAM": "vscode", + "TERM_PROGRAM_VERSION": "1.43.0", + "LANG": "en_GB.UTF-8", + "COLORTERM": "truecolor" + }, + "sharedObjects": [ + "C:\\Program Files\\nodejs\\node.exe", + "C:\\windows\\SYSTEM32\\ntdll.dll", + "C:\\windows\\System32\\KERNEL32.DLL", + "C:\\windows\\System32\\KERNELBASE.dll", + "C:\\windows\\System32\\WS2_32.dll", + "C:\\windows\\System32\\RPCRT4.dll", + "C:\\windows\\System32\\PSAPI.DLL", + "C:\\windows\\System32\\ADVAPI32.dll", + "C:\\windows\\SYSTEM32\\dbghelp.dll", + "C:\\windows\\System32\\msvcrt.dll", + "C:\\windows\\System32\\ucrtbase.dll", + "C:\\windows\\System32\\sechost.dll", + "C:\\windows\\SYSTEM32\\IPHLPAPI.DLL", + "C:\\windows\\System32\\USER32.dll", + "C:\\windows\\SYSTEM32\\USERENV.dll", + "C:\\windows\\System32\\win32u.dll", + "C:\\windows\\System32\\profapi.dll", + "C:\\windows\\System32\\GDI32.dll", + "C:\\windows\\System32\\gdi32full.dll", + "C:\\windows\\System32\\msvcp_win.dll", + "C:\\windows\\System32\\CRYPT32.dll", + "C:\\windows\\System32\\MSASN1.dll", + "C:\\windows\\System32\\bcrypt.dll", + "C:\\windows\\SYSTEM32\\WINMM.dll", + "C:\\windows\\SYSTEM32\\WINMMBASE.dll", + "C:\\windows\\System32\\cfgmgr32.dll", + "C:\\windows\\System32\\bcryptPrimitives.dll", + "C:\\windows\\System32\\IMM32.DLL", + "C:\\windows\\System32\\powrprof.dll", + "C:\\windows\\System32\\UMPDC.dll", + "C:\\windows\\SYSTEM32\\CRYPTBASE.DLL", + "C:\\windows\\system32\\uxtheme.dll", + "C:\\windows\\System32\\combase.dll", + "C:\\windows\\system32\\mswsock.dll", + "C:\\windows\\System32\\kernel.appcore.dll", + "C:\\windows\\System32\\NSI.dll", + "C:\\windows\\SYSTEM32\\dhcpcsvc6.DLL", + "C:\\windows\\SYSTEM32\\dhcpcsvc.DLL", + "C:\\windows\\SYSTEM32\\DNSAPI.dll", + "C:\\windows\\system32\\napinsp.dll", + "C:\\windows\\system32\\pnrpnsp.dll", + "C:\\windows\\System32\\winrnr.dll", + "C:\\windows\\system32\\NLAapi.dll", + "C:\\windows\\system32\\wshbth.dll" + ] +} \ No newline at end of file diff --git a/Week3/homework/js-exercises/CreditCardValidator.js b/Week3/homework/js-exercises/CreditCardValidator.js new file mode 100644 index 000000000..a9ab1f248 --- /dev/null +++ b/Week3/homework/js-exercises/CreditCardValidator.js @@ -0,0 +1,79 @@ +'use strict'; + +// numOfDigitIs16 function test if number of input is 16 objects +function numOfDigitIs16 (input) { + + if ( input.length == 16 ) + return true; + else + return false; +} + +// inputIsNumber function test if input's objects are integers +function inputIsNumber (input){ + + let flag = true; + + for ( let i of input ) { + if ( ! (i >= '0' && i <= '9') ) { + flag = false; + break; + } + } + return flag; +} + +// validate if the input have a set of more than an object +function differentDigits (input) { + + let mySet = new Set (); + + for ( let i of input) + mySet.add (i); // set only store the same object once + + if ( mySet.size > 1) + return true; + else + return false; +} + +// validate if the last object of input is an even integer +function finalEven (input) { + + if ( input [ input.length - 1 ] % 2 == 0 ) + return true; + else + return false; +} + +// validate if the sum of input digits bigger than 16 +function sumOfDigits (input) { + + let sum = 0; + + for ( let i of input) + { + sum = sum + Number.parseInt(i); + } + if ( sum > 16) + return true; + else + return false; +} + + +function creditCardValidator (input) { + + if ( numOfDigitIs16(input) && inputIsNumber(input) && differentDigits(input) && finalEven(input) && sumOfDigits(input) ) + return `your card number ( ${input} ) is VALID`; + else + return `your card number ( ${input} ) is INVALID`; +} + + +console.log( creditCardValidator('9999777788880000') ); +console.log( creditCardValidator('6666666666661666') ); +console.log( creditCardValidator('a92332119c011112') ); +console.log( creditCardValidator('4444444444444444') ); +console.log( creditCardValidator('1111111111111110') ); +console.log( creditCardValidator('6666666666666661') ); \ No newline at end of file diff --git a/Week3/homework/js-exercises/addToShoppingCart.js b/Week3/homework/js-exercises/addToShoppingCart.js new file mode 100644 index 000000000..27a89a7c5 --- /dev/null +++ b/Week3/homework/js-exercises/addToShoppingCart.js @@ -0,0 +1,14 @@ +'use strict'; + +let cart = ['bananas','milk']; +function addToShoppingCart (item) { +if ( cart.length >= 3 ) + cart.shift(); + +cart.push (item); + +return `You bought ${cart}!` +} +console.log ( addToShoppingCart ("apples") ) ; +console.log ( addToShoppingCart ("Cheese") ) ; +console.log ( addToShoppingCart ("Bread") ) ; \ No newline at end of file diff --git a/Week3/homework/js-exercises/calculateDogAge.js b/Week3/homework/js-exercises/calculateDogAge.js new file mode 100644 index 000000000..75fb6928e --- /dev/null +++ b/Week3/homework/js-exercises/calculateDogAge.js @@ -0,0 +1,13 @@ +'use strict'; + +function calculateDogAge (age) { + if ( Number.isInteger (age) ) + return `Your doggie is ${ age * 7 } years old in dog years!`; + else { + return `Enter integer numbers`; +} +} +console.log (calculateDogAge (2) ); +console.log (calculateDogAge (5) ); +console.log (calculateDogAge (1.5) ); +console.log (calculateDogAge ("one year") ); \ No newline at end of file diff --git a/Week3/homework/js-exercises/calculateTotalPrice.js b/Week3/homework/js-exercises/calculateTotalPrice.js new file mode 100644 index 000000000..b43cffe3d --- /dev/null +++ b/Week3/homework/js-exercises/calculateTotalPrice.js @@ -0,0 +1,32 @@ +'use strict'; + +function myTypeOf (input) { + // return !( isNaN(input) ) + if ( typeof (input) === "number") + return true; + else + return false; +} +function calculateTotalPrice (obj) { + let sum = 0; + let flag = true; + + const arr = Object.values(obj); + for ( let i of arr) { + if ( !(myTypeOf(i)) ) { + flag = false; + break; + } + } + if ( flag ) { + for ( let i of arr ) { + sum += i; + } + return sum.toFixed(2); + } + else + return " object does not contains properties that contain number values"; + +} + let cartForParty = {banana : 2.4 , appel : 1.75 , water : 12 , chips : 3.25 , sugar : 4.15} +console.log (calculateTotalPrice(cartForParty)); diff --git a/Week3/homework/js-exercises/giveCompliment.js b/Week3/homework/js-exercises/giveCompliment.js new file mode 100644 index 000000000..1d1541e7c --- /dev/null +++ b/Week3/homework/js-exercises/giveCompliment.js @@ -0,0 +1,12 @@ +'use strict'; + +function giveCompliment (name) { +let complimentList = ['You\'re an awesome friend.','You\'re a gift to those around you.', + 'You are awesome!','I like your style.','You have the best laugh.','I appreciate you.', + 'You\'re strong.','Your perspective is refreshing.','I\'m grateful to know you.','You deserve a hug right now.']; +return ` ${ name } ${ complimentList [ Math.floor ( Math.random () * complimentList.length ) ] } `; +} + +console.log( giveCompliment ("Alaska") ); +console.log( giveCompliment ("Alaska") ); +console.log( giveCompliment ("Alaska") ); \ No newline at end of file diff --git a/Week3/homework/js-exercises/tellFortune.js b/Week3/homework/js-exercises/tellFortune.js new file mode 100644 index 000000000..47e45c51d --- /dev/null +++ b/Week3/homework/js-exercises/tellFortune.js @@ -0,0 +1,28 @@ +'use strict'; + +let nameList = ['Alaa','Baraa','Alex','Mo','Anna']; +let childrenList = [1,2,3,4,5,6,7]; +let locationList = ['Amsterdam','Utrecht','Den Hague']; +let jobList = ['Software Developer','Doctor','Teacher','CEO'] + + +function tellFortune(children,name,location,job) { +let numOfChildren , myName, myLocation , myJob; + for (let item of children) + { numOfChildren = children[Math.floor(Math.random() * children.length)]; + } + for (let item of name) + { myName = name[Math.floor (Math.random() * name.length)]; + } + for (let item of location) + { myLocation = location[Math.floor (Math.random() * location.length)]; + } + for (let item of job) + { myJob = job[Math.floor (Math.random() * job.length)]; + } + return `You will be a ${myJob} in ${myLocation}, and married to ${myName} with ${numOfChildren} kids.`; +} + +console.log(tellFortune (childrenList,nameList,locationList,jobList) ); +console.log(tellFortune (childrenList,nameList,locationList,jobList) ); +console.log(tellFortune (childrenList,nameList,locationList,jobList) ); \ No newline at end of file