Skip to content

Instantly share code, notes, and snippets.

@LukeSkyRunner
Created December 30, 2019 16:06
Show Gist options
  • Save LukeSkyRunner/bef7221fab793d4ab8a804a273b37b33 to your computer and use it in GitHub Desktop.
Save LukeSkyRunner/bef7221fab793d4ab8a804a273b37b33 to your computer and use it in GitHub Desktop.
Javascript String Practice
const str1 = "Web Dev is amazing!";
// => look for each of these separately:
// - "development",
console.log(str1.includes("development"));
// - "Development",
console.log(str1.includes("Development"));
// - "web",
console.log(str1.includes("web"));
// - "ing",
console.log(str1.includes("ing"));
// - "Web"
console.log(str1.includes("Web"));
//concatenate two strings
const str2 = "Hey!"
const str3 = "How are you?"
let concatenate = str2 + str3
console.log (concatenate)
//Take out half of sentance:
let sentence = "This is one meaningless sentence which needs to be cut in half.";
let half = sentence.length / 2
console.log (sentence.slice (0, half))
// end result: This is one meaningless sentence
// ***hint: first calculate the length of
// the sentence so you can calculate its half
//Capitalize:
//a) the whole name of the city where you are now
//b) the first letter of the city
//c) capitalize the middle letter if the city has an odd number of letters or two middle letters if the city has even number of letters (hint: you can use .charAt() and .slice())
let city = "Lisbon"
console.log (city.charAt(0))
console.log (city.slice(2,4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment