From 65a9f64613a11942e9bb82dbc139dda07c6cc0f5 Mon Sep 17 00:00:00 2001 From: Louis McHugh Date: Thu, 12 Jun 2025 20:50:03 +0200 Subject: [PATCH] answered string method question pt.2 --- index.js | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index aa0a0fd..125c72b 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const string1 = "My favorite dessert is jello"; // Your code here... - +// console.log(string1.indexOf("j")); /******************************************* @@ -19,7 +19,8 @@ const string2 = "ABCDEFGHJKLO"; // Your code here... - +const newString = string2[2]+string2[11]+string2[11]+string2[10]; +// console.log(newString); /***************************************************** @@ -31,7 +32,7 @@ const string3 = "Na"; // Your code here... - +// console.log(string3.repeat(4) + " Batman!"); /******************************************* @@ -42,6 +43,17 @@ const string3 = "Na"; const fruit = "banana apple mango orange lemon kiwi watermelon grapes pear pineapple"; // Your code here... +/* Method 1 +console.log(fruit.slice(13, 18)); +*/ + +/* Method 2 +let start = fruit.indexOf("mango"); +let end = start + "mango".length; + +console.log(fruit.slice(start, end)); +*/ + @@ -58,13 +70,22 @@ const funnyHeadline2 = "Students Cook & Serve Grandparents"; // Check the first headline // Your code here ... - - +/* +if (funnyHeadline1.includes(`oxygen`)) { + console.log("The string includes the word 'oxygen'"); +} else { + console.log("The string does not include the word 'oxygen'"); +} +*/ // Check the second headline // Your code here ... - - - +/* +if (funnyHeadline2.includes(`oxygen`)) { + console.log("The string includes the word 'oxygen'"); +} else { + console.log("The string does not include the word 'oxygen'"); +} +*/ /******************************************* Iteration 6 | String Length *******************************************/ @@ -75,7 +96,13 @@ 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 ... + +const lastChar = string4.length - 1; + +console.log(string4[lastChar]); +*/