|
1 | 1 | // Iteration 1: Names and Input
|
2 |
| -let hacker1 = "Stefan"; |
| 2 | + |
| 3 | + |
| 4 | +let hacker1 = "Alex"; |
3 | 5 | console.log(`The driver's
|
4 | 6 | name is ${hacker1}`);
|
5 | 7 |
|
6 |
| -let hacker2 = "Juan"; |
| 8 | +let hacker2 = "Alexander"; |
7 | 9 | console.log("The navigator's name is " + hacker2);
|
8 | 10 |
|
9 | 11 | // Iteration 2: Conditionals
|
@@ -38,4 +40,96 @@ switch (true) {
|
38 | 40 | );
|
39 | 41 | }
|
40 | 42 |
|
| 43 | +console.log("ITERATION 3") |
| 44 | + |
41 | 45 | // Iteration 3: Loops
|
| 46 | +// 3.1 Print all the characters of the driver's name, separated by a space and in capitals i.e. "J O H N" |
| 47 | +// let driver = []; |
| 48 | +// for(let i=0; i<hacker1.length; i++){ |
| 49 | +// driver.push(hacker1[i]) |
| 50 | +// } |
| 51 | +console.log( hacker1.split('').join(' ').toUpperCase() ) |
| 52 | + |
| 53 | + |
| 54 | +console.log('3.2 Print all the characters of the navigators name, in reverse order. i.e. "nhoJ"') |
| 55 | + |
| 56 | +let navigatorReverse = [] |
| 57 | +for(let i=hacker2.length-1; i>=0; i--){ |
| 58 | + console.log(i) |
| 59 | + navigatorReverse.push(hacker2[i]) |
| 60 | +} |
| 61 | + |
| 62 | +console.log( navigatorReverse.join('') ) |
| 63 | + |
| 64 | +// console.log( hacker2.split('').reverse().join('') ) |
| 65 | + |
| 66 | +console.log(`3.3 Depending on the lexicographic order of the strings, print: |
| 67 | +- The driver's name goes first. |
| 68 | +- Yo, the navigator goes first definitely. |
| 69 | +- What?! You both have the same name?`) |
| 70 | + |
| 71 | +let names = [hacker1, hacker2]; |
| 72 | +console.log(names) |
| 73 | + |
| 74 | +names.sort(); |
| 75 | +console.log(names) |
| 76 | + |
| 77 | + |
| 78 | +// if(hacker1.length < hacker2.length){ |
| 79 | +// console.log(`The ${hacker1} name goes first.`) |
| 80 | +// } |
| 81 | +// else if (hacker2.length < hacker1.length){ |
| 82 | +// console.log(`Yo, the ${hacker2} goes first definitely.`) |
| 83 | +// } |
| 84 | +// else { |
| 85 | +// console.log(`What?! You both have the same name?`) |
| 86 | +// } |
| 87 | + |
| 88 | + |
| 89 | +if ( hacker1.localeCompare(hacker2) === -1){ |
| 90 | + console.log(`The ${hacker1} name goes first.`) |
| 91 | +} |
| 92 | +else if ( hacker1.localeCompare(hacker2) === 1) { |
| 93 | + console.log(`Yo, the ${hacker2} goes first definitely.`) |
| 94 | +} |
| 95 | +else { |
| 96 | + console.log(`What?! You both have the same name?`) |
| 97 | +} |
| 98 | + |
| 99 | +// hacker1.localeCompare(hacker2) === -1 ? : "true dogs" : "false cats" |
| 100 | +// // 2 + 2 === 5 ? "true dogs" : "false cats" |
| 101 | +// // "false cats" |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +let par1 = `25 shmeckles? I-I-I-I don't even know what that- what is that? Is that a lot? There's pros and cons to every alternate timeline. Fun facts about this one – It's got giant, telepathic spiders, 11 9/11s, and the best ice cream in the multiverse! This is because you give Morty Smith bad grades, bitch! Listen, Morty, I hate to break it to you but what people call love is just a chemical reaction that compels animals to breed` |
| 107 | + |
| 108 | +let par2 = `If you break the rules, try to leave or lose the game, you will die. Just like Saaaaw. Not today bitch! Flip the pickle over. Wow, so your origin is what? You fell into a vat of redundancy?` |
| 109 | + |
| 110 | +let par3 = `"And"? What more youtube do you want tacked on to this? I turned myself into a pickle, and 9/11 was an inside job?" He threatened to turn me in to the government, so I made him and the government go away! I'm Mr. Crowbar, and here is my friend, who is also a crowbar! Must… continue… moving… in… ways… that… lead… to… dying… with… you.` |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +console.log((par1 + par2 + par3).split(' ').length) |
| 116 | + |
| 117 | +let par = par1 + par2 + par3 //Made it into one string |
| 118 | + |
| 119 | +console.log( par.split('you').length - 1 ) |
| 120 | + |
| 121 | +//RegExp |
| 122 | +console.log( par.match(/you/g).length ) |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +let phraseToCheck = "A man, a plan, a canal, Panama!" |
| 127 | +phraseToCheck = phraseToCheck.replace(/[,! ]/g,"").toLowerCase() |
| 128 | + |
| 129 | + |
| 130 | +let reversePhrase = phraseToCheck.split('').reverse().join('') |
| 131 | + |
| 132 | +console.log(phraseToCheck) |
| 133 | +console.log(reversePhrase) |
| 134 | +console.log(phraseToCheck == reversePhrase) |
| 135 | + |
0 commit comments