From 89bc3c2b17155f96e4ed3880ee284b53683d1c80 Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Mon, 10 Feb 2020 16:41:08 +0200 Subject: [PATCH 1/8] changing to master branch and adding js1w2 exercises --- Week1/homework/js calculator/index.css | 29 +++ Week1/homework/js calculator/index.html | 44 ++++ Week1/homework/js calculator/main.js | 20 ++ .../homework/js-exercises/10_compareArrays.js | 15 ++ Week1/homework/js-exercises/1_logHello.js | 11 + .../homework/js-exercises/2_ErrorDebugging.js | 2 + Week1/homework/js-exercises/3_LogNumber.js | 18 ++ Week1/homework/js-exercises/4_LogString.js | 18 ++ Week1/homework/js-exercises/5_RndNum.js | 23 ++ Week1/homework/js-exercises/6_arrayAnimals.js | 23 ++ Week1/homework/js-exercises/7_stringLength.js | 9 + Week1/homework/js-exercises/8_typeChecker.js | 37 +++ Week1/homework/js-exercises/9_remainder.js | 9 + Week2/homework/1_removeComma.js | 13 + Week2/homework/2_oddEven.js | 12 + Week2/homework/3_recipeCard.js | 18 ++ Week2/homework/4_readingList.js | 40 ++++ package-lock.json | 226 ++++++++++++++++++ 18 files changed, 567 insertions(+) create mode 100644 Week1/homework/js calculator/index.css create mode 100644 Week1/homework/js calculator/index.html create mode 100644 Week1/homework/js calculator/main.js create mode 100644 Week1/homework/js-exercises/10_compareArrays.js create mode 100644 Week1/homework/js-exercises/1_logHello.js create mode 100644 Week1/homework/js-exercises/2_ErrorDebugging.js create mode 100644 Week1/homework/js-exercises/3_LogNumber.js create mode 100644 Week1/homework/js-exercises/4_LogString.js create mode 100644 Week1/homework/js-exercises/5_RndNum.js create mode 100644 Week1/homework/js-exercises/6_arrayAnimals.js create mode 100644 Week1/homework/js-exercises/7_stringLength.js create mode 100644 Week1/homework/js-exercises/8_typeChecker.js create mode 100644 Week1/homework/js-exercises/9_remainder.js create mode 100644 Week2/homework/1_removeComma.js create mode 100644 Week2/homework/2_oddEven.js create mode 100644 Week2/homework/3_recipeCard.js create mode 100644 Week2/homework/4_readingList.js create mode 100644 package-lock.json diff --git a/Week1/homework/js calculator/index.css b/Week1/homework/js calculator/index.css new file mode 100644 index 000000000..509f95b5e --- /dev/null +++ b/Week1/homework/js calculator/index.css @@ -0,0 +1,29 @@ +body{ + width: 1920px; + height: 1024px; +} + +.main, table{ +width: 400px; +height: 400px; +background-color: gainsboro; +} + + + +.textview{ +background-color: greenyellow; +width: 100%; +border:4px; +font-size: 40px; +border-style:inset; + text-align: center; +} + +.button{ + background-color: silver; + width: 100%; + height: 100%; + font-size: 30px; + border-radius: 15px; +} diff --git a/Week1/homework/js calculator/index.html b/Week1/homework/js calculator/index.html new file mode 100644 index 000000000..2dbb13980 --- /dev/null +++ b/Week1/homework/js calculator/index.html @@ -0,0 +1,44 @@ + + + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/Week1/homework/js calculator/main.js b/Week1/homework/js calculator/main.js new file mode 100644 index 000000000..3e96fbbcf --- /dev/null +++ b/Week1/homework/js calculator/main.js @@ -0,0 +1,20 @@ +function insert(num){ +document.form.textview.value = document.form.textview.value+num +} + +function equal(){ +var exp = document.form.textview.value + +if(exp){ document.form.textview.value = eval(exp) + } + } +function clean(){ + document.form.textview.value = "" +} + +function back(){ + var exp = document.form.textview.value + + document.form.textview.value = exp.substring(0,exp.length-1) + } + diff --git a/Week1/homework/js-exercises/10_compareArrays.js b/Week1/homework/js-exercises/10_compareArrays.js new file mode 100644 index 000000000..5b21cfa59 --- /dev/null +++ b/Week1/homework/js-exercises/10_compareArrays.js @@ -0,0 +1,15 @@ +'use strict' + +//Declare 2 variables, that each hold an array. The first array should have 4 items, the second 7 items +const array1=["one",1,true,{name:"array1"}]; +const array2=["one",2,3,"four","five",6,7]; + +//Find out how to get the length of each array. Write a console.log statement that shows the length of each array +console.log("Array1 has length of "+ array1.length); +console.log("Array2 has length of "+ array2.length); + +//Write a conditional statement that checks if both are of equal length. If they are, log to the console They are the same!, if not log Two different sizes +if(array1==array2){ + console.log("They are the same!"); +} +else console.log("Two different sizes"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/1_logHello.js b/Week1/homework/js-exercises/1_logHello.js new file mode 100644 index 000000000..09dba1901 --- /dev/null +++ b/Week1/homework/js-exercises/1_logHello.js @@ -0,0 +1,11 @@ +'use strict' +console.log("Hello, World!") +console.log("Geia sou, Kosme!") +console.log("Ciao, Mondo!") +console.log("Bonjour, le Monde!") +console.log("Hallo, Welt!") +console.log("Hola, Mundo!") +console.log("Hei, Verden!") +console.log("salve, Mundi!") +console.log("Selam, Dunya!") +console.log("Witaj, Wiecie!") \ No newline at end of file diff --git a/Week1/homework/js-exercises/2_ErrorDebugging.js b/Week1/homework/js-exercises/2_ErrorDebugging.js new file mode 100644 index 000000000..abfb656f2 --- /dev/null +++ b/Week1/homework/js-exercises/2_ErrorDebugging.js @@ -0,0 +1,2 @@ +'use strict' +console.log("I'm Awesome") \ No newline at end of file diff --git a/Week1/homework/js-exercises/3_LogNumber.js b/Week1/homework/js-exercises/3_LogNumber.js new file mode 100644 index 000000000..4d1813ab8 --- /dev/null +++ b/Week1/homework/js-exercises/3_LogNumber.js @@ -0,0 +1,18 @@ +'use strict' +/*First, declare your variable numberX. Do not initialize it (which means, don't give it a value) yet.*/ +var numberX + +/*Add a console.log statement that explains in words what you think the value of x is, like in this example.*/ +console.log("The value of the numberX is null") + +/*Add a console.log statement that logs the value of numberX.*/ +console.log(numberX) + +/*Now initialize your variable numberX with a number (also called an integer in computer science terms).*/ +numberX=5 + +/*Next, add a console.log statement that explains what you think the value of numberX is.*/ +console.log("Now the numberX has a value") + +/*Add a console.log statement that logs the value of numberX.*/ +console.log(numberX) \ No newline at end of file diff --git a/Week1/homework/js-exercises/4_LogString.js b/Week1/homework/js-exercises/4_LogString.js new file mode 100644 index 000000000..f6c3341db --- /dev/null +++ b/Week1/homework/js-exercises/4_LogString.js @@ -0,0 +1,18 @@ +'use strict' +/*Declare a variable myString and assign a string to it. Use your full name, including spaces, as the content for the string.*/ +let myString="Kiriakos Mouzakis"; + +/*Write a console.log statement in which you explain in words what you think the value of the string is.*/ +console.log("The value of myString is my full name"); + +/*Now console.log the variable myString.*/ +console.log(myString); + +/*Now reassign to the variable myString a new string.*/ +myString=("Now I am Batman"); + +/*Just like what you did before write a console.log statement that explains in words what you think will be logged to the console.*/ +console.log("Now the string has changed"); + +/*Now console.log myString again.*/ +console.log(myString); diff --git a/Week1/homework/js-exercises/5_RndNum.js b/Week1/homework/js-exercises/5_RndNum.js new file mode 100644 index 000000000..07916021f --- /dev/null +++ b/Week1/homework/js-exercises/5_RndNum.js @@ -0,0 +1,23 @@ +'use strict' +/*Declare a variable z and assign the number 7.25 to it.*/ +let z=7.25; + +/*Write a console.log statement in which you log the value of z.*/ +console.log("'Z' value is "+z); + +/*Declare another variable a that has the value of z but rounded to the nearest integer.*/ +let a; +a=Math.round(z); + +/*Write a console.log statement in which you log the value of a.*/ +console.log("'A' has the same value but is rounded "+a); + +/*So now we have z and a find a way to compare the two values and store the highest of the two in a new variable. */ +/*Write a console.log statement in which you log the value of the highest value.*/ +function bigger(){ + if(a>z) {console.log("'A' is bigger with value of "+a) + } + else {console.log("'Z' is bigger with value of "+z) + } +} +bigger() \ No newline at end of file diff --git a/Week1/homework/js-exercises/6_arrayAnimals.js b/Week1/homework/js-exercises/6_arrayAnimals.js new file mode 100644 index 000000000..deb47a15c --- /dev/null +++ b/Week1/homework/js-exercises/6_arrayAnimals.js @@ -0,0 +1,23 @@ +'use strict' +/*Declare variable and assign to it an empty array. +Make sure that the name of the variable indicates it contains more than 1 item. For example items instead of item.*/ +let array1=new Array; + +/*Write a console.log statement that explains in words what you think the value of the array is.*/ +console.log("The value of the array is empty") + +/*Write a console.log statement that logs the array.*/ +console.log(array1); + +/*Create a new variable with an array that has 3 of your favorite animals, each in a different string. +Make sure the name of the variables says something about what the variable contains.*/ +let animals=["lion","tiger","panther"]; + +/*Write a console.log statement that logs the second array.*/ +console.log(animals); + +/*Add a statement that adds another string ("Piglet)" to the array of animals.*/ +animals.push("Piglet"); + +/*Write a console.log statement that logs the second array!*/ +console.log(animals); \ No newline at end of file diff --git a/Week1/homework/js-exercises/7_stringLength.js b/Week1/homework/js-exercises/7_stringLength.js new file mode 100644 index 000000000..da5138ec0 --- /dev/null +++ b/Week1/homework/js-exercises/7_stringLength.js @@ -0,0 +1,9 @@ +'use strict' +/*/Declare a variable called mySentence and initialize it with the following string: "Programming is so interesting!".*/ +let mySentence="Programming is so interesting!"; + +/*Figure out (using Google) how to get the length of mySentence.*/ +let stringLength=mySentence.length; + +/*Write a console.log statement to log the length of mySentence.*/ +console.log(stringLength); \ No newline at end of file diff --git a/Week1/homework/js-exercises/8_typeChecker.js b/Week1/homework/js-exercises/8_typeChecker.js new file mode 100644 index 000000000..895098bb0 --- /dev/null +++ b/Week1/homework/js-exercises/8_typeChecker.js @@ -0,0 +1,37 @@ +'use strict' +/*Write a program that checks the data types of two variables and logs to the console SAME TYPE if they are the same type. +If they are different types log Not the same....*/ +/*Declare 4 variables: 2 must be strings and 2 must be objects*/ +let string1="social"; +let string2="hackers"; +let fname={firstname:"kiriakos"}; +let lname={lastname:"mouzakis"}; + +/*Create 6 conditional statements, where for each you check if the data type of one variable is the same as the other*/ +if (typeof string1 === typeof string2) {console.log("string1 and string2 are the same type");} +if (typeof string1 === typeof fname) {console.log("string1 and fname are the same type");} +if (typeof string1 === typeof lname) {console.log("string1 and lname are the same type");} +if (typeof string2 === typeof fname) {console.log("string2 and fname are the same type");} +if (typeof string2 === typeof lname) {console.log("string2 and lname are the same type");} +if (typeof fname === typeof lname) {console.log("fname and lname are the same type");} + +/*Find out how to check the type of a variable*/ +console.log("You can check a type of a variable with the typeof() command eg.. The type of fname is an "+typeof fname); + +/*Write 2 console.log statements to log the type of 2 variables, each with a different data type*/ +console.log(typeof(string1)); +console.log(typeof(lname)); + +/*Now compare the types of your different variables with one another*/ +/*Log Not the same... when the types are different*/ +let num1=1; +if (typeof string1 === typeof string2) {console.log("string1 and string2 are the same type")} else {console.log("Not the same type"); } +if (typeof string1 === typeof fname) {console.log("string1 and fname are the same type");} else {console.log("Not the same type"); } +if (typeof string1 === typeof lname) {console.log("string1 and lname are the same type");} else {console.log("Not the same type"); } +if (typeof string2 === typeof fname) {console.log("string2 and fname are the same type");} else {console.log("Not the same type"); } +if (typeof string2 === typeof lname) {console.log("string2 and lname are the same type");} else {console.log("Not the same type"); } +if (typeof fname === typeof lname) {console.log("fname and lname are the same type");} else {console.log("Not the same type"); } +if (typeof num1 === typeof string1) {console.log("num1 and string1 are the same type");} else {console.log("Not the same type"); } +if (typeof num1 === typeof string2) {console.log("num1 and string2 are the same type");} else {console.log("Not the same type"); } +if (typeof num1 === typeof fname) {console.log("num1 and fname are the same type");} else {console.log("Not the same type"); } +if (typeof num1 === typeof lname) {console.log("num1 and lname are the same type");} else {console.log("Not the same type"); } \ No newline at end of file diff --git a/Week1/homework/js-exercises/9_remainder.js b/Week1/homework/js-exercises/9_remainder.js new file mode 100644 index 000000000..0abce4e30 --- /dev/null +++ b/Week1/homework/js-exercises/9_remainder.js @@ -0,0 +1,9 @@ +'use strict' +/*For each of these, write in comments what the answer is followed by how you came to that conclusion*/ + +/*If x equals 7, and the only other statement is x = x % 3, what would be the value of x after the calculation?*/ +console.log("At first x will have the value 7, then after the division it will take the value of the modulus (% symbol) and will be 1"); +/*If y equals 21, and the only other statement is y = y % 4, what would be the value of y after the calculation?*/ +console.log("At first y will have the value 21, then after the division it will take the value of the modulus (% symbol) and will be 1"); +/*If z equals 13, and the only other statement is z = z % 2, what would be the value of z after the calculation?*/ +console.log("At first z will have the value 13, then after the division it will take the value of the modulus (% symbol) and will be 1"); diff --git a/Week2/homework/1_removeComma.js b/Week2/homework/1_removeComma.js new file mode 100644 index 000000000..e90473ef4 --- /dev/null +++ b/Week2/homework/1_removeComma.js @@ -0,0 +1,13 @@ +'use strict' +/*let myString = "hello,this,is,a,difficult,to,read,sentence"; +Add the variable to your file.*/ +let myString = "hello,this,is,a,difficult,to,read,sentence" + +//Log the length of myString. +console.log(myString.length); + +//The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces. (use Google!) +let newString=myString.replace(/,/g,' '); + +//After replacing the commas, log myString to see if you succeeded. +console.log(newString); \ No newline at end of file diff --git a/Week2/homework/2_oddEven.js b/Week2/homework/2_oddEven.js new file mode 100644 index 000000000..67498763c --- /dev/null +++ b/Week2/homework/2_oddEven.js @@ -0,0 +1,12 @@ +'use strict' +/*Report whether or not a number is odd/even! +Create a for loop, that iterates from 0 to 20.*/ + +for(let i=0; i<21; i++){ + /*Create a conditional statement that checks if the value of the counter variable is odd or even. + If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!. + If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.*/ + if(i%2) { + console.log("The number "+i+" is odd."); + } + else console.log("The number "+i+" is even.");} diff --git a/Week2/homework/3_recipeCard.js b/Week2/homework/3_recipeCard.js new file mode 100644 index 000000000..29d8af90b --- /dev/null +++ b/Week2/homework/3_recipeCard.js @@ -0,0 +1,18 @@ +'use strict' +/*Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript! +Declare a variable that holds an object (your meal recipe).*/ +//Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property. +const tost={ + Title:"Tost", + Servings:1, + Ingredients:["Slices of bread","cheese","ham","tomato"] +} +//Log each property out seperately, using a loop (for, while or do/while) + +let recipe=[tost] + +for (let i of recipe){ + console.log("Title: "+i.Title); + console.log("Servings: "+i.Servings); + console.log("Ingredients: "+"\n"+i.Ingredients[0]+"\n"+i.Ingredients[1]+"\n"+i.Ingredients[2]+"\n"+i.Ingredients[3]); +} diff --git a/Week2/homework/4_readingList.js b/Week2/homework/4_readingList.js new file mode 100644 index 000000000..184702765 --- /dev/null +++ b/Week2/homework/4_readingList.js @@ -0,0 +1,40 @@ +'use strict' +/*Keep track of which books you read and which books you want to read! +Declare a variable that holds an array of 3 objects, where each object describes a book and +has properties for the title (string), author (string), and alreadyRead (boolean indicating if you read it yet).*/ +const lord_of_the_rings={ + title:"The Fellowship of the Ring", + author:"J. R. R. Tolkien", + alreadyRead:false +} +const game_of_thrones={ + title:"A Song of Ice and Fire", + author:"George R. R. Martin", + alreadyRead:true +} +const harry_potter={ + title:"The Philosopher's Stone", + author:"J. K. Rowling", + alreadyRead:true +} +//Loop through the array of books. +var myBooks=[lord_of_the_rings,game_of_thrones,harry_potter]; + +myBooks.forEach(item=> console.log(item)); + +//For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien". +myBooks.forEach(item=> { + return console.log(item.title + " by " + item.author+ "\n"); +}); + +/*Create a conditional statement to change the log depending on whether you read it yet or not. +If you read it, log a string like You already read "The Hobbit" right after the log of the book details +If you haven't read it log a string like You still need to read "The Lord of the Rings"*/ +for (let item of myBooks){ + if (item.alreadyRead == true){ + + console.log("You already read: " + item.title + "\n"); +}else{ + console.log("You still nead to read: "+ item.title + "\n"); +} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..6213ff0b3 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,226 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", + "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", + "requires": { + "exit": "0.1.2", + "glob": "^7.1.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "requires": { + "date-now": "^0.1.4" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=" + }, + "dom-serializer": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", + "integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==", + "requires": { + "domelementtype": "^2.0.1", + "entities": "^2.0.0" + }, + "dependencies": { + "domelementtype": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", + "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==" + }, + "entities": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", + "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==" + } + } + }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" + }, + "domhandler": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", + "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=" + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "htmlparser2": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", + "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", + "requires": { + "domelementtype": "1", + "domhandler": "2.3", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "jshint": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.11.0.tgz", + "integrity": "sha512-ooaD/hrBPhu35xXW4gn+o3SOuzht73gdBuffgJzrZBJZPGgGiiTvJEgTyxFvBO2nz0+X1G6etF8SzUODTlLY6Q==", + "requires": { + "cli": "~1.0.0", + "console-browserify": "1.1.x", + "exit": "0.1.x", + "htmlparser2": "3.8.x", + "lodash": "~4.17.11", + "minimatch": "~3.0.2", + "shelljs": "0.3.x", + "strip-json-comments": "1.0.x" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +} From 4c4235aa4bd384ed7227865b4585862a76bc692d Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Mon, 10 Feb 2020 21:20:23 +0200 Subject: [PATCH 2/8] exercise 5 --- Week2/homework/5_wantDrinks.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Week2/homework/5_wantDrinks.js diff --git a/Week2/homework/5_wantDrinks.js b/Week2/homework/5_wantDrinks.js new file mode 100644 index 000000000..17d80f6e7 --- /dev/null +++ b/Week2/homework/5_wantDrinks.js @@ -0,0 +1,15 @@ +/*You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. +Let's go get them a drink.*/ + +//Declare a variable that holds an empty array, called drinkTray. +/*There are 3 different types of drinks: +const drinkTypes = ["cola", "lemonade", "water"];*/ + +//Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. +/*The drinkTray can only hold at most two instances of the same drink type, +for example it can only hold 2 colas, 2 lemonades, 2 waters.*/ + +/*If there are already two instances of a drinkType then start with the next drink in the array. +Your drinkTray should contain 2 cola, 2 lemonade and 1 water. +Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" +(For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!")*/ \ No newline at end of file From c5c6d9872b3c725b3a839310129d8b1e5015f4d9 Mon Sep 17 00:00:00 2001 From: mouzakiskir <56204532+mouzakiskir@users.noreply.github.com> Date: Tue, 11 Feb 2020 14:46:06 +0200 Subject: [PATCH 3/8] Delete 5_wantDrinks.js --- Week2/homework/5_wantDrinks.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Week2/homework/5_wantDrinks.js diff --git a/Week2/homework/5_wantDrinks.js b/Week2/homework/5_wantDrinks.js deleted file mode 100644 index 17d80f6e7..000000000 --- a/Week2/homework/5_wantDrinks.js +++ /dev/null @@ -1,15 +0,0 @@ -/*You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. -Let's go get them a drink.*/ - -//Declare a variable that holds an empty array, called drinkTray. -/*There are 3 different types of drinks: -const drinkTypes = ["cola", "lemonade", "water"];*/ - -//Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. -/*The drinkTray can only hold at most two instances of the same drink type, -for example it can only hold 2 colas, 2 lemonades, 2 waters.*/ - -/*If there are already two instances of a drinkType then start with the next drink in the array. -Your drinkTray should contain 2 cola, 2 lemonade and 1 water. -Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" -(For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!")*/ \ No newline at end of file From b9e84ee47a6e8b9fc1f38d3ce97afed4ef540ff3 Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Tue, 11 Feb 2020 14:57:33 +0200 Subject: [PATCH 4/8] fix --- Week2/homework/5_drinkTray.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Week2/homework/5_drinkTray.js diff --git a/Week2/homework/5_drinkTray.js b/Week2/homework/5_drinkTray.js new file mode 100644 index 000000000..2cd5e6979 --- /dev/null +++ b/Week2/homework/5_drinkTray.js @@ -0,0 +1,10 @@ +//You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink. + +//Declare a variable that holds an empty array, called drinkTray. +//There are 3 different types of drinks: +//const drinkTypes = ["cola", "lemonade", "water"]; + +/*Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. +If there are already two instances of a drinkType then start with the next drink in the array. +Your drinkTray should contain 2 cola, 2 lemonade and 1 water. +Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!")*/ \ No newline at end of file From 321d6f96d32b87ce0349eb162dbeb92b5c41d82f Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Tue, 11 Feb 2020 17:10:10 +0200 Subject: [PATCH 5/8] exersice 5 --- Week2/homework/5_drinkTray.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Week2/homework/5_drinkTray.js b/Week2/homework/5_drinkTray.js index 2cd5e6979..436fe0f2e 100644 --- a/Week2/homework/5_drinkTray.js +++ b/Week2/homework/5_drinkTray.js @@ -1,10 +1,27 @@ //You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink. //Declare a variable that holds an empty array, called drinkTray. +let drinkTray=[]; //There are 3 different types of drinks: //const drinkTypes = ["cola", "lemonade", "water"]; +const drinkTypes = ["cola", "lemonade", "water"]; -/*Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. +/*Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable. +The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. If there are already two instances of a drinkType then start with the next drink in the array. -Your drinkTray should contain 2 cola, 2 lemonade and 1 water. -Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!")*/ \ No newline at end of file +Your drinkTray should contain 2 cola, 2 lemonade and 1 water.*/ +let drinksNum = 0; + +function checkDrinks (x){ + return x == drinkTypes[drinksNum] +}; + +for (let i = 0; i < 5; i++){ + drinkTray.push(drinkTypes[drinksNum]); + if (drinkTray.filter(checkDrinks).length === 2){ + drinksNum += 1; + } +} + +//Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!") +console.log("Hey guys, I brought a " + drinkTray[0] + ", " + drinkTray[1] + ", " + drinkTray[2] + ", " + drinkTray[3] + ", " + drinkTray[4] + "!"); From 3802cf35906297113b247e76497907b481e087c6 Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Tue, 11 Feb 2020 17:11:51 +0200 Subject: [PATCH 6/8] fix --- package-lock.json | 226 ---------------------------------------------- 1 file changed, 226 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 6213ff0b3..000000000 --- a/package-lock.json +++ /dev/null @@ -1,226 +0,0 @@ -{ - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "cli": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz", - "integrity": "sha1-IoF1NPJL+klQw01TLUjsvGIbjBQ=", - "requires": { - "exit": "0.1.2", - "glob": "^7.1.1" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "console-browserify": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", - "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", - "requires": { - "date-now": "^0.1.4" - } - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "date-now": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", - "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=" - }, - "dom-serializer": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", - "integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==", - "requires": { - "domelementtype": "^2.0.1", - "entities": "^2.0.0" - }, - "dependencies": { - "domelementtype": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", - "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==" - }, - "entities": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", - "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==" - } - } - }, - "domelementtype": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", - "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" - }, - "domhandler": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", - "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", - "requires": { - "domelementtype": "1" - } - }, - "domutils": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", - "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", - "requires": { - "dom-serializer": "0", - "domelementtype": "1" - } - }, - "entities": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", - "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=" - }, - "exit": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", - "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "htmlparser2": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", - "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", - "requires": { - "domelementtype": "1", - "domhandler": "2.3", - "domutils": "1.5", - "entities": "1.0", - "readable-stream": "1.1" - } - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" - }, - "jshint": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.11.0.tgz", - "integrity": "sha512-ooaD/hrBPhu35xXW4gn+o3SOuzht73gdBuffgJzrZBJZPGgGiiTvJEgTyxFvBO2nz0+X1G6etF8SzUODTlLY6Q==", - "requires": { - "cli": "~1.0.0", - "console-browserify": "1.1.x", - "exit": "0.1.x", - "htmlparser2": "3.8.x", - "lodash": "~4.17.11", - "minimatch": "~3.0.2", - "shelljs": "0.3.x", - "strip-json-comments": "1.0.x" - } - }, - "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "readable-stream": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - }, - "shelljs": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", - "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=" - }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" - }, - "strip-json-comments": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", - "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=" - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - } - } -} From dc3c5422d8c12dc66a62e54b39ecbf5e03dcd6a7 Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Sun, 16 Feb 2020 22:27:42 +0200 Subject: [PATCH 7/8] javascript 1 exercises and projects completed --- .../1_removeComma.js | 0 .../{ => js1_week2_exercises}/2_oddEven.js | 0 .../{ => js1_week2_exercises}/3_recipeCard.js | 0 .../4_readingList.js | 0 .../{ => js1_week2_exercises}/5_drinkTray.js | 20 +++--- Week2/homework/project_gradeCalc/gradeCalc.js | 45 ++++++++++++++ .../creditCardValidator.js | 61 +++++++++++++++++++ Week3/homework/js-exercises/1_compliment.js | 21 +++++++ Week3/homework/js-exercises/2_dogYears.js | 21 +++++++ .../homework/js-exercises/3_fortuneTeller.js | 43 +++++++++++++ Week3/homework/js-exercises/4_superMarket.js | 27 ++++++++ Week3/homework/js-exercises/5_totalCost.js | 27 ++++++++ 12 files changed, 252 insertions(+), 13 deletions(-) rename Week2/homework/{ => js1_week2_exercises}/1_removeComma.js (100%) rename Week2/homework/{ => js1_week2_exercises}/2_oddEven.js (100%) rename Week2/homework/{ => js1_week2_exercises}/3_recipeCard.js (100%) rename Week2/homework/{ => js1_week2_exercises}/4_readingList.js (100%) rename Week2/homework/{ => js1_week2_exercises}/5_drinkTray.js (70%) create mode 100644 Week2/homework/project_gradeCalc/gradeCalc.js create mode 100644 Week3/homework/credit card project/creditCardValidator.js create mode 100644 Week3/homework/js-exercises/1_compliment.js create mode 100644 Week3/homework/js-exercises/2_dogYears.js create mode 100644 Week3/homework/js-exercises/3_fortuneTeller.js create mode 100644 Week3/homework/js-exercises/4_superMarket.js create mode 100644 Week3/homework/js-exercises/5_totalCost.js diff --git a/Week2/homework/1_removeComma.js b/Week2/homework/js1_week2_exercises/1_removeComma.js similarity index 100% rename from Week2/homework/1_removeComma.js rename to Week2/homework/js1_week2_exercises/1_removeComma.js diff --git a/Week2/homework/2_oddEven.js b/Week2/homework/js1_week2_exercises/2_oddEven.js similarity index 100% rename from Week2/homework/2_oddEven.js rename to Week2/homework/js1_week2_exercises/2_oddEven.js diff --git a/Week2/homework/3_recipeCard.js b/Week2/homework/js1_week2_exercises/3_recipeCard.js similarity index 100% rename from Week2/homework/3_recipeCard.js rename to Week2/homework/js1_week2_exercises/3_recipeCard.js diff --git a/Week2/homework/4_readingList.js b/Week2/homework/js1_week2_exercises/4_readingList.js similarity index 100% rename from Week2/homework/4_readingList.js rename to Week2/homework/js1_week2_exercises/4_readingList.js diff --git a/Week2/homework/5_drinkTray.js b/Week2/homework/js1_week2_exercises/5_drinkTray.js similarity index 70% rename from Week2/homework/5_drinkTray.js rename to Week2/homework/js1_week2_exercises/5_drinkTray.js index 436fe0f2e..f3718723e 100644 --- a/Week2/homework/5_drinkTray.js +++ b/Week2/homework/js1_week2_exercises/5_drinkTray.js @@ -1,7 +1,8 @@ +'use strict' //You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink. - //Declare a variable that holds an empty array, called drinkTray. -let drinkTray=[]; +let drinkTray=new Array(5); + //There are 3 different types of drinks: //const drinkTypes = ["cola", "lemonade", "water"]; const drinkTypes = ["cola", "lemonade", "water"]; @@ -10,18 +11,11 @@ const drinkTypes = ["cola", "lemonade", "water"]; The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters. If there are already two instances of a drinkType then start with the next drink in the array. Your drinkTray should contain 2 cola, 2 lemonade and 1 water.*/ -let drinksNum = 0; - -function checkDrinks (x){ - return x == drinkTypes[drinksNum] -}; - +let x = 0; for (let i = 0; i < 5; i++){ - drinkTray.push(drinkTypes[drinksNum]); - if (drinkTray.filter(checkDrinks).length === 2){ - drinksNum += 1; - } + drinkTray[i] = drinkTypes[x]; + if(i%2 == 1) x++; } //Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!") -console.log("Hey guys, I brought a " + drinkTray[0] + ", " + drinkTray[1] + ", " + drinkTray[2] + ", " + drinkTray[3] + ", " + drinkTray[4] + "!"); +console.log("Hey guys, I brought a " + drinkTray.join()+"."); \ No newline at end of file diff --git a/Week2/homework/project_gradeCalc/gradeCalc.js b/Week2/homework/project_gradeCalc/gradeCalc.js new file mode 100644 index 000000000..c5a92e174 --- /dev/null +++ b/Week2/homework/project_gradeCalc/gradeCalc.js @@ -0,0 +1,45 @@ +'use strict' +/*In this project you'll write a function that calculates grades, +based on the American grading system! Let's say a student did a test and they got a 60 out of 100, this function will: +1.convert the score into a percentage +2.calculate what grade corresponds with that percentage, and +3.shows in the command line the result: the grade and the percentage +In this example this is what we would expect the function to return in the command line: + +You got a D (60%)! +When writing the function, make use of the following grade scores: + +Grade A (90% - 100%) +Grade B (80% - 89%) +Grade C (70% - 79%) +Grade D (60% - 69%) +Grade E (50% - 59%) +Grade F (0% - 49%)*/ + + + +function grade(score){ + if(score >= 90 && score <= 100){ + console.log(`You got a A (${score}%)!`) + } + else if(score >= 80 && score <= 89){ + console.log(`You got a B (${score}%)!`) + } + else if(score >= 70 && score <= 79){ + console.log(`You got a C (${score}%)!`) + } + else if(score >= 60 && score <= 69){ + console.log(`You got a D (${score}%)!`) + } + else if(score >= 50 && score <= 59){ + console.log(`You got a E (${score}%)!`) + } + else if(score >= 0 && score <= 49){ + console.log(`You got a F (${score}%)!`) + } +} + +grade(Math.floor(Math.random() * 100)); + + + diff --git a/Week3/homework/credit card project/creditCardValidator.js b/Week3/homework/credit card project/creditCardValidator.js new file mode 100644 index 000000000..24e4bbdff --- /dev/null +++ b/Week3/homework/credit card project/creditCardValidator.js @@ -0,0 +1,61 @@ +'use strict'; + +function cardValidator(number) { + var number; + let even = number.match(/^(d*[0-9]){15}[02468]/gs); //Takes 15 digits and the last one must be even number, if not returns null. + let sameNum= number.match(/^(\d)(?!\1+$)\d{15}$/gs); //Checks if the numbers are the same, if not returns null. + + function overSixteen() { //Function that checks if the sum off all numbers are over 16, if not returns null. + let sum = 0; + for (let i = 0; i < number.length; i++) { + sum += parseInt(number[i]); + } + if(sum<16){ + return null; + } + } + + + if(even && sameNum && overSixteen != null) { + console.log("Valid card: "+number); + } + else + console.log("Invalid card: "+number) + } + +cardValidator("1234567891234566"); +cardValidator("6666666666661666"); +cardValidator("a92332119c011112"); +cardValidator("4444444444444444"); +cardValidator("1111111111111110"); +cardValidator("6666666666666661"); + + +/*In this project you'll write a script that validates whether or not a credit card number is valid. + +Here are the rules for a valid number: + +- Number must be 16 digits, all of them must be numbers +- You must have at least two different digits represented (all of the digits cannot be the same) +- The final digit must be even +- The sum of all the digits must be greater than 16 +- The following credit card numbers are valid: + +9999777788880000 +6666666666661666 + +The following credit card numbers are invalid: + +a92332119c011112 (invalid characters) +4444444444444444 (only one type of number) +1111111111111110 (sum less than 16) +6666666666666661 (odd final number) + +These are the requirements your project needs to fulfill: + +- Make a JavaScript file with a name that describes its contents +- Create a function with a descriptive name, for example: `doSomething` or `calcAnotherThing` +- Write at least 2 comments that explain to others what a line of code is meant to do +- Make the return value of the function a template string, so you can insert variables! +- Use `node` from the command line to test if your code works as expected +*/ \ No newline at end of file diff --git a/Week3/homework/js-exercises/1_compliment.js b/Week3/homework/js-exercises/1_compliment.js new file mode 100644 index 000000000..489850655 --- /dev/null +++ b/Week3/homework/js-exercises/1_compliment.js @@ -0,0 +1,21 @@ +'use strict' + +//1. Write a function named `giveCompliment` + function giveCompliment(name){ + +/*- It takes 1 argument: your name +- Inside the function create an array with 10 strings. Each string should be a compliment, like `"great"`, `"awesome"` +- Write logic that randomly selects a compliment +- Return a string: "You are [COMPLIMENT], [YOUR_NAME]!*/ + + let compliment=["great","good","awesome","the best","excellent","superb","amazing","flawless","victorious","the man"]; + const randomCompliment = compliment[Math.floor(Math.random() * compliment.length)]; + return console.log(`You are ${randomCompliment},${name}!`) + } +//2. Call the function three times, giving each function call the same argument: your name. + for(let i=0; i<3; i++){ + giveCompliment("Kiriako") + } + + + diff --git a/Week3/homework/js-exercises/2_dogYears.js b/Week3/homework/js-exercises/2_dogYears.js new file mode 100644 index 000000000..acac06540 --- /dev/null +++ b/Week3/homework/js-exercises/2_dogYears.js @@ -0,0 +1,21 @@ +'use strict' +//You know how old your dog is in human years, but what about dog years? Calculate it! + +/*1. Write a function named `calculateDogAge`. +- It takes 1 argument: your puppy's age (number). +- Calculate your dog's age based on the conversion rate of 1 human year to 7 dog years. +- Return a string: "Your doggie is [CALCULATED_VALUE] years old in dog years!"*/ +function calculateDogAge(number){ + let dogAge=number*7; + + console.log(`Your doggie is ${dogAge} years old in dog years!`) +} + +//2. Call the function three times with different sets of values.*/ + +for(let i=0; i<3; i++){ + function getRandomInt(max) { + return Math.floor(Math.random() * Math.floor(max)); + } + calculateDogAge(getRandomInt(15)); +} \ No newline at end of file diff --git a/Week3/homework/js-exercises/3_fortuneTeller.js b/Week3/homework/js-exercises/3_fortuneTeller.js new file mode 100644 index 000000000..77c59d444 --- /dev/null +++ b/Week3/homework/js-exercises/3_fortuneTeller.js @@ -0,0 +1,43 @@ +'use strict' +//Why pay a fortune teller when you can just program your fortune yourself? +/*1. Write a function named `tellFortune`. +- It takes 4 arguments: number of children (number), partner's name (string), geographic location (string), job title (string). +- Randomly select values from the arrays. +- Return a string: "You will be a [JOB_TITLE] in [LOCATION], and married to [PARTNER_NAME] with [NUMBER_KIDS] kids." +2. Create 4 arrays, `numChildren`, `partnerNames`, `locations` and `jobs`. Give each array 5 random values that make sense*/ + +let partnerNames=[ + "Maria", + "Anna", + "Jeniffer", + "Penelope", + "Eleftheria"]; + +let locations=[ + "Athens", + "New York", + "Tokyo", + "Berlin"]; + +let jobs=[ + "doctor", + "lawer", + "police-officer", + "electrician", + "farmer"]; + +function tellFortune(randomJobs,randomLocations,randomPartner,numChildren){ + + numChildren=[getRandomInt(5)]; + function getRandomInt(max) { + return Math.floor(Math.random() * Math.floor(max)); + } + randomPartner = partnerNames[Math.floor(Math.random() * partnerNames.length)]; + randomLocations = locations[Math.floor(Math.random() * locations.length)]; + randomJobs = jobs[Math.floor(Math.random() * jobs.length)]; + + return(`You will be a ${randomJobs} in ${randomLocations}, and married to ${randomPartner} with ${numChildren} kids.`) +} + +//3. Call the function 1 time, by passing the arrays as the argument.*/ +console.log(tellFortune()) \ No newline at end of file diff --git a/Week3/homework/js-exercises/4_superMarket.js b/Week3/homework/js-exercises/4_superMarket.js new file mode 100644 index 000000000..1c74d3f6a --- /dev/null +++ b/Week3/homework/js-exercises/4_superMarket.js @@ -0,0 +1,27 @@ +'use strict' +/*Let's do some grocery shopping! We're going to get some things to cook dinner with. However, you like to spend your money and always buy too many things. +So when you have more than 3 items in your shopping cart the first item gets taken out. +1. Write a function named `addToShoppingCart`. +- It takes in 1 argument: a grocery item (string) +- Add grocery item to array. If the amount of items is more than 3 remove the first one in the array +- Return a string: "You bought [LIST_OF_GROCERY_ITEMS]!" +2. Create an array with 2 predefined strings: `"bananas"` and `"milk"`*/ + +let shoppingItems=[ + "bananas", + "milk" +] +function addToShoppingCart(product){ + if(shoppingItems.length > 2) + shoppingItems.shift() + shoppingItems.push(product) + return(`You bought ${shoppingItems}!`) +} + +//3. Call the function 3 times, each time with a different string as the argument. +console.log(addToShoppingCart("bacon")); +console.log(addToShoppingCart("salmon")); +console.log(addToShoppingCart("beef")); + + + diff --git a/Week3/homework/js-exercises/5_totalCost.js b/Week3/homework/js-exercises/5_totalCost.js new file mode 100644 index 000000000..881cad044 --- /dev/null +++ b/Week3/homework/js-exercises/5_totalCost.js @@ -0,0 +1,27 @@ +'use strict' +/*You want to buy a couple of things from the supermarket to prepare for a party. After scanning all the items the cashier gives you the total price, +but the machine a broken! Let's write her a function that does it for her instead! + +1. Write a function called `calculateTotalPrice` +- It takes 1 argument: an object that contains properties that only contain number values +- Add all the number values together +- Return a number: the total price of all items +2. Create an object named `cartForParty` with 5 properties. Each property should be a grocery item (like `beers` or `chips`) and hold a number value (like `1.75` or `0.99`)*/ +function calculateTotalPrice(cartForParty){ + cartForParty={ + beer:1.75, + chips:0.99, + coca_cola:3.90, + pizza:6.70, + party_cake:15.70 + } + let total = 0; + for (let property in cartForParty) { + total += cartForParty[property]; +} + return total; +} +//3. Call the function 1 time, giving it the object `cartForParty` as an argument*/ +console.log("Total price: "+calculateTotalPrice()+"€"); + + From eab4808559a7b87d6ae206a6d11e8f1845fe89b6 Mon Sep 17 00:00:00 2001 From: mouzakiskir Date: Mon, 17 Feb 2020 00:00:29 +0200 Subject: [PATCH 8/8] fix --- Week3/homework/credit card project/creditCardValidator.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Week3/homework/credit card project/creditCardValidator.js b/Week3/homework/credit card project/creditCardValidator.js index 24e4bbdff..bfacf1ddb 100644 --- a/Week3/homework/credit card project/creditCardValidator.js +++ b/Week3/homework/credit card project/creditCardValidator.js @@ -14,8 +14,7 @@ function cardValidator(number) { return null; } } - - + if(even && sameNum && overSixteen != null) { console.log("Valid card: "+number); }