From bdbdc7709124b394e48b02a3b73534f308889bc1 Mon Sep 17 00:00:00 2001 From: Dali Rojas Date: Mon, 2 Apr 2018 15:50:12 -0400 Subject: [PATCH] assignment finished --- .DS_Store | Bin 0 -> 6148 bytes starter-code/basic-algorithms.js | 155 ++++++++++++++++++++++++++++++- 2 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cf9a80298cd6ffabc1263f4f1f298b9515f2c1a6 GIT binary patch literal 6148 zcmeHK%}(1u5S|TbSqG}-fCNWhD)j(WAQc=Cl1Y<84wX<{!J$-OW2;y)UKBe-kf!o$ zv~SQy;R$%0GPAphhyqeCpcc(Yv)}CQe7o|u*8Tv1X!WCYfI0w3bi#^*#XUy-$_Zul1!ptW=06Rz7XwBgSBsgp2OA@Z+n2H@}kkW5tX^>iSs}|$MH>v zl#XMO%xbF;DPZZtPWtL|`X3*-0A&C$q_%Wu|qy2odiSHth4A3wDeAn@1M_S)hY zeqr#SP#1nLOI7v_bH@BJkC7E%1z3ScSHNyOa^cZu;t5y*R^WeAfc6I$ozSyb8q`|{ z7WxT*NY_Yh7}JH3IIcy{VrdY2(1f8P8mh2Q3}NWl?%F)hVrkIOLDa6$k8 literal 0 HcmV?d00001 diff --git a/starter-code/basic-algorithms.js b/starter-code/basic-algorithms.js index 82f20d8ba..8c796ce77 100644 --- a/starter-code/basic-algorithms.js +++ b/starter-code/basic-algorithms.js @@ -1,7 +1,158 @@ // Names and Input +//Dali and Neil + +//Create a variable with drivers name +var hacker1 = "Neil"; + + + +//Print out drivers name +console.log("The driver's name is: " + hacker1); + + + +//Ask for Navigators name +var hacker2 = prompt("Please enter navigator's name:"); + + + +//Print the Navigators name +console.log("The navigator's name is: " + hacker2); + + + +//Print response depending on who has longer name +if (hacker1.length === hacker2.length) +{ + console.log("Wow, you both got equally long names, " + hacker1.length + " characters!"); +} + + + +else if (hacker1.length > hacker2.length) +{ + console.log("The driver has the longest name, it has " + hacker1.length + " characters"); +} + + + +else +{ + console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters."); +} + + + +//Print all the characters of the driver's name, separated by a space and in capitals ie. "J O H N" + +var s = ""; +var t = ""; + +for (i = 0; i < hacker1.length; i++) +{ + s += hacker1[i].toUpperCase() + " "; + +} +console.log(s); + + +//Print all the characters of the navigator's name, in reverse order. ie. "nhoJ" + +for (i = hacker2.length-1; i >= 0; i--) +{ + t += hacker2[i] + +} +console.log(t); + + + + +//Lexographic + +var x = [hacker1.toLowerCase(), hacker2.toLowerCase()]; + +console.log(x.sort()); +x = x.sort(); + +for (i = 0; i< x.length; i++) +{ + if (x[0] === x[1]) + { + console.log("What?! You both got the same name?!"); + break; + } + else if (x[0] === hacker1.toLowerCase()) + { + console.log("The driver's name goes first."); + break; + } + else + { + console.log("Yo, the navigator goes first definitely"); + break; + } +} + + + +//BONUS PALINDROME + +var palindrome = prompt("Please enter a string:"); + +var re = /[\W_0-9]/g; + +var palindromeConverted = palindrome.toLowerCase().replace(re,""); + +var palindromeReversed = palindromeConverted.split("").reverse().join(""); + +if (palindromeReversed === palindromeConverted) +{ + console.log("It is a palindrome!"); +} +else +{ + console.log("It is not a palindrome!"); +} +console.log(palindromeReversed); + + + + + +//10 Lorem Ipsum + +var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin at nisi id velit consequat efficitur. Morbi efficitur ornare nisi rutrum iaculis. Suspendisse condimentum nisi non neque porttitor, vitae congue nisl feugiat. Phasellus pretium non elit a consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel dui felis. Curabitur eu vestibulum urna. Fusce vitae lorem augue. Ut vel vestibulum sem, in condimentum risus. Aenean mollis, est non ullamcorper gravida, est dolor pulvinar neque, et laoreet urna sapien quis felis. Phasellus urna nibh, tristique a semper a, fringilla non lacus. Integer sit amet rutrum magna. Etiam a ipsum fringilla, dapibus ligula at, semper tellus. Fusce ut nibh in sapien maximus egestas. Vivamus eu tristique nisl, eu molestie ligula. Pellentesque mauris libero, vulputate id luctus sit amet, mattis a urna. Sed pellentesque, neque at vulputate viverra, odio felis volutpat ante, eget fermentum libero orci quis lectus. Nulla eros massa, ultricies suscipit varius sit amet, faucibus id lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis orci dui, tempus eu maximus at, faucibus non felis. Donec vulputate turpis consectetur nunc pretium, sed bibendum elit blandit. Quisque in molestie leo, ut mattis elit. Mauris vehicula sed dui nec scelerisque.Nunc eu erat non justo efficitur ultrices suscipit sed mi. Phasellus interdum mi a varius finibus. Fusce ac lectus et urna porta viverra. Integer id enim placerat, auctor est eu, volutpat sapien. In in ipsum felis. Ut quis aliquam urna. Cras fringilla, ante et laoreet pulvinar, ipsum massa gravida risus, in faucibus quam nulla in leo. Aliquam pretium fringilla velit in semper. Proin nec ipsum suscipit, ultricies purus malesuada, dapibus ante. Mauris vehicula sem id metus ultricies, nec maximus magna auctor."; + + var re = /[\_.,0-9]/g; + + text = text.replace(re,""); + console.log(text); + text = text.split(" ") + console.log(text.length+1); + + var count = 0; + + for(i = 0; i <= text.length; i++) + { + if (text[i] === "et") + { + count++; + } + } + console.log(count); + + + + + + + + + + + -//Conditionals -// Lorem ipsum generator