Skip to content
Open

js #137

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
// Write code that prints out to the console the index of the character “j” in

const string1 = "My favorite dessert is jello";

// Your code here...
let stringJ = string1.indexOf("j");

console.log(typeof stringJ);
console.log(stringJ);



Expand All @@ -16,9 +18,15 @@ const string1 = "My favorite dessert is jello";
// Make a new string with the text "COOL" by using only the characters available in the provided string and the bracket notation

const string2 = "ABCDEFGHJKLO";

// Your code here...

let letterC = string2.charAt(2);
let letterO = string2.slice(-1);
let letterL = string2.slice(-2,-1);
let wordCool = letterC + letterO.repeat(2)+ letterL;
console.log(letterC);
console.log(letterO);
console.log(letterL);
console.log(wordCool);



Expand All @@ -30,7 +38,8 @@ const string2 = "ABCDEFGHJKLO";
const string3 = "Na";

// Your code here...

let sentence = string3.repeat(4) + "Batman!";
console.log(sentence);



Expand All @@ -42,27 +51,39 @@ const string3 = "Na";
const fruit = "banana apple mango orange lemon kiwi watermelon grapes pear pineapple";

// Your code here...
let wordKiwi = fruit.search("kiwi");
console.log(wordKiwi);

let myFavouriteWord = fruit.slice(32,36);
console.log(myFavouriteWord);


/***************************************************
Iteration 5 | Check If Strings Include a Word
***************************************************/
// Using the string method .include(), check if the below strings with funny newspaper headlines include the word "oxygen".
// Using the string method .include(), check if the below strings with funny newspaper headlines include the word "".
// If a string includes the word "oxygen" print to the console message "The string includes the word 'oxygen'",
// else print the message "The string does not include the word 'oxygen'".

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 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'");
}


/*******************************************
Expand All @@ -75,7 +96,10 @@ const string4 = "zEAWrTC9EgtxmK9w1";

// a) Print the string length
// Your code here ...

let lastLetter = string4.slice(-1);
let lastLetterString = lastLetter.toString();
console.log(string4.length,lastLetterString);
console.log(typeof lastLetterString,typeof lastLetterString);

// b) Print the last character in the string
// Your code here ...