diff --git a/index.js b/index.js index aa0a0fd..45a1ec2 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,8 @@ const string1 = "My favorite dessert is jello"; // Your code here... - - - +console.log(string1[23]); +console.log(string1.charAt(23)); /******************************************* Iteration 2 | Concatenate Characters @@ -19,8 +18,7 @@ const string2 = "ABCDEFGHJKLO"; // Your code here... - - +console.log(string2[2], string2[11], string2[11], string2[10]); /***************************************************** Iteration 3 | Repeat a String and Concatenate @@ -31,19 +29,20 @@ const string3 = "Na"; // Your code here... - - +console.log(string3 + string3 + string3 + string3 + " Batman!"); /******************************************* Iteration 4 | Fruite Slice *******************************************/ // Using the string method .slice(), access and print to the console the name of your favorite fruit from a given string -const fruit = "banana apple mango orange lemon kiwi watermelon grapes pear pineapple"; +const fruit = + "banana apple mango orange lemon kiwi watermelon grapes pear pineapple"; // Your code here... - +let favoriteFruit = fruit.slice(13, 18); +console.log(favoriteFruit); /*************************************************** Iteration 5 | Check If Strings Include a Word @@ -55,15 +54,23 @@ const fruit = "banana apple mango orange lemon kiwi watermelon grapes pear pinea const funnyHeadline1 = "Breathing oxygen linked to staying alive"; const funnyHeadline2 = "Students Cook & Serve Grandparents"; - // Check the first headline // Your code here ... +if (funnyHeadline1.includes("oxygen")) { + console.log("The first string includes the word 'oxygen'"); +} else { + console.log("didn't find the word oxygen in string 1"); +} // Check the second headline // Your code here ... - +if (funnyHeadline2.includes("oxygen")) { + console.log("The second string includes the word 'oxygen'"); +} else { + console.log("didn't find the word oxygen in string 2"); +} /******************************************* Iteration 6 | String Length @@ -72,10 +79,12 @@ const funnyHeadline2 = "Students Cook & Serve Grandparents"; const string4 = "zEAWrTC9EgtxmK9w1"; - // a) Print the string length // Your code here ... +console.log(string4.length); // b) Print the last character in the string // Your code here ... + +console.log(string4[string4.length - 1]);