From 97285a22d27ecfa6194252fa772fb28669c5140e Mon Sep 17 00:00:00 2001 From: SandwichExpert <46784674+SandwichExpert@users.noreply.github.com> Date: Wed, 7 Aug 2019 12:31:48 +0200 Subject: [PATCH 1/2] PAR FWD - Justine & Xavier - lab-javascript-basic --- starter-code/basic-algorithms.js | 86 +++++++++++++++++++++++++++++--- starter-code/index.html | 14 ++++++ 2 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 starter-code/index.html diff --git a/starter-code/basic-algorithms.js b/starter-code/basic-algorithms.js index 82f20d8ba..f9fc8522b 100644 --- a/starter-code/basic-algorithms.js +++ b/starter-code/basic-algorithms.js @@ -1,7 +1,79 @@ -// Names and Input - - -//Conditionals - - -// Lorem ipsum generator +// Names and Input +var hacker1="Zacharia"; + + console.log(`the hacker's name is ${hacker1}`); + +var hacker2= window.prompt("And you are?"); + +console.log(`the navigator's name is ${hacker2}`); + +if (hacker1.length > hacker2.length){ + console.log(`The driver has the longest name, it has ${hacker1.length} letters`); + } + else if (hacker1.length == hacker2.length){ + console.log(`Wow, you both have equally long names, ${hacker1.length} characters each!`); + } + else{ + console.log(`Navigator has the longest name, it has ${hacker2.length} characters.`); + } + + for (i=0;i=0 ; i--){ + console.log(hacker2[i]); +} + +var names =[hacker1,hacker2]; + +for (i=0;i + + + + + + Document + + + + + + + \ No newline at end of file From 54f52f04c825450d159df59f0ef5b6f9e1076751 Mon Sep 17 00:00:00 2001 From: SandwichExpert <46784674+SandwichExpert@users.noreply.github.com> Date: Wed, 7 Aug 2019 13:03:44 +0200 Subject: [PATCH 2/2] added last version of js file --- starter-code/basic-algorithms.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/starter-code/basic-algorithms.js b/starter-code/basic-algorithms.js index f9fc8522b..797072b11 100644 --- a/starter-code/basic-algorithms.js +++ b/starter-code/basic-algorithms.js @@ -64,7 +64,7 @@ var count = 0; function countWords(words) { const tmp = words.split(/\W/); - var count = 0; + let count = 0; for (let i = 0; i < tmp.length; i += 1) { if (tmp[i]) count++; } @@ -72,6 +72,18 @@ function countWords(words) { } countWords(lorem); +function countEt(words){ + const dude = words.split(/\W/); + let newCount = 0; + for (let i = 0; i < dude.length; i+=1){ + if (dude[i] == "et"){ + + newCount++;} + } + console.log(newCount); +} +countEt(lorem); + //Conditionals