From cec1efc452f0f6fc72ce2d96f99bd5ae8e8a2fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Fern=C3=A1ndez=20Ardura?= Date: Mon, 3 Apr 2017 18:04:09 +0200 Subject: [PATCH 1/2] done first part --- starter-code/basic-algorithms.js | 94 +++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/starter-code/basic-algorithms.js b/starter-code/basic-algorithms.js index 82f20d8ba..2c20c6979 100644 --- a/starter-code/basic-algorithms.js +++ b/starter-code/basic-algorithms.js @@ -1,7 +1,97 @@ -// Names and Input +var hacker1 = "Marc"; +var hacker2 = ""; +hacker2 = prompt("What´s is the navigator´s name"); + console.log("The navigator´s name is " + hacker2); +if(hacker1.length > hacker2.length){ + console.log("the driver´s has the longuest name it has " + hacker1.length + " characters"); +}else if( hacker1.length < hacker2.length){ + console.log("yo, navigator got the longuest name, it has "+ hacker2.length + " characters"); -//Conditionals + console.log("wow, you both got equally long names, "+ hacker1.length +" characters"); +}else{ +} + /*var seperator = "", result1 = ""; + //for(var i =0; i < hacker1.length; i++){ + + result1 = hacker1.split(seperator); + console.log(result1); + */ + + for (var i=0; i=0){ + chainHacker2=chainHacker2 + hacker2.charAt(x); + x--; + } + document.write(chainHacker2); + } + invertWord(hacker2); + + + + /*var newArray = [hacker1, hacker2]; + function alfabet() { + newArray.sort(); + if (hacker1 == newArray[0]){ + console.log("The driver's name goes first "+ hacker1); + }else if(hacker2 == newArray[0]){ + console.log("Yo, the navigator goes first definitely "+ hacker2); + + }else{ + console.log("What?! You both got the same name?"); + } + console.log(newArray); + } + alfabet();*/ + var array = [hacker1, hacker2]; +console.log("Unordered array ---", array, "------------‘"); + +array.sort(function(a,b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + console.log("Compare " + a + " and " + b ); + + if( a == b) { + console.log("Both are the same"); + return 0; + } + if( a > b) { + console.log("Comparison result, 1 --- move "+b+" to before "+a); + return 1; + } + console.log("Comparison result, -1 --- move "+a+" to before "+b+" "); + return -1; + + +}); + +console.log("Ordered array ---", array, "------------"); + +// return logic // Lorem ipsum generator From ec134af54af530820e0f29940845830de739f929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Fern=C3=A1ndez=20Ardura?= Date: Mon, 3 Apr 2017 19:15:35 +0200 Subject: [PATCH 2/2] done 1-9 --- starter-code/basic-algorithms.js | 68 ++++++++++++++------------------ starter-code/index.html | 13 ++++++ 2 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 starter-code/index.html diff --git a/starter-code/basic-algorithms.js b/starter-code/basic-algorithms.js index 2c20c6979..d83660ea1 100644 --- a/starter-code/basic-algorithms.js +++ b/starter-code/basic-algorithms.js @@ -8,17 +8,11 @@ if(hacker1.length > hacker2.length){ }else if( hacker1.length < hacker2.length){ console.log("yo, navigator got the longuest name, it has "+ hacker2.length + " characters"); - console.log("wow, you both got equally long names, "+ hacker1.length +" characters"); + }else{ +console.log("WOOOW, you both got equally long names, "+ hacker1.length +" characters"); } - /*var seperator = "", result1 = ""; - - //for(var i =0; i < hacker1.length; i++){ - - result1 = hacker1.split(seperator); - console.log(result1); - */ for (var i=0; i hacker2.length){ } - /*function separateUppercase(hacker1){ - var x= 0; - var separateName = ""; - - while (x hacker2.length){ } invertWord(hacker2); - - - /*var newArray = [hacker1, hacker2]; - function alfabet() { - newArray.sort(); - if (hacker1 == newArray[0]){ - console.log("The driver's name goes first "+ hacker1); - }else if(hacker2 == newArray[0]){ - console.log("Yo, the navigator goes first definitely "+ hacker2); - - }else{ - console.log("What?! You both got the same name?"); - } - console.log(newArray); - } - alfabet();*/ var array = [hacker1, hacker2]; console.log("Unordered array ---", array, "------------‘"); @@ -93,5 +57,31 @@ array.sort(function(a,b) { console.log("Ordered array ---", array, "------------"); -// return logic +var palindrome = prompt("type in your word"); +var invertedWord = ""; +var as1 = palindrome.replace(" ",""); //remove space +var as2 = as1.replace(/[^0-9a-z]/gi, ""); //remove symbols +var as3 = as2.toLowerCase(); //lower case + +console.log("show the word without space and signs: " + as3); //shows the word + +function CheckPalindrome(as3){ //function to check if palindrome + var x= as3.length; + var invertedWord = ""; + + while(x>=0){ + invertedWord=invertedWord + as3.charAt(x); + x--; + } + console.log(invertedWord); //inverst the word + + if (invertedWord === as3) //checks if the inverted word is the same as as3 + { + console.log("true"); + } else { + console.log("not true"); + } +} + +CheckPalindrome(as3); // Lorem ipsum generator diff --git a/starter-code/index.html b/starter-code/index.html new file mode 100644 index 000000000..03d2f22e5 --- /dev/null +++ b/starter-code/index.html @@ -0,0 +1,13 @@ + + + + + + + + + + +