day 2 - exercise: level 1

pull/914/head
Doris Wiebe 2 years ago
parent 165551480a
commit cb7cd404a7

@ -1 +1,54 @@
// this is your main.js script
// this is your main.js script
// ### Exercise: Level 1
let challenge = "30 Days Of JavaScript";
console.log(challenge);
console.log(challenge.length);
console.log(challenge.toUpperCase());
console.log(challenge.toLowerCase());
console.log(challenge.substring(0, 2));
console.log(challenge.substr(3, 4));
console.log(challenge.substr(3, 18));
console.log(challenge.includes("Script"));
console.log(challenge.split());
console.log(challenge.split(" "));
let testString = "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon";
console.log(testString.split(", "));
console.log(challenge.replace("JavaScript", "Python"));
console.log(challenge.charAt(15));
console.log(challenge.charCodeAt(11));
console.log(challenge.indexOf("a"));
console.log(challenge.lastIndexOf("a"));
let because =
"You cannot end a sentence with because because because is a conjunction";
console.log(because.indexOf("because"));
console.log(because.lastIndexOf("because"));
console.log(because.search("because"));
let removeWhitespace = "\t30 Days Of JavaScript\t";
console.log(removeWhitespace);
console.log(removeWhitespace.trim());
console.log(challenge.startsWith("30"));
console.log(challenge.endsWith("Script"));
const regex = /a/g;
const search = challenge.match(regex);
console.log(search);
const firstPart = "30 Days of";
const secondPart = "JavaScript";
console.log(firstPart.concat(secondPart));
console.log(challenge.repeat(2));

@ -1,22 +1,24 @@
// match: it takes a substring or regular expression pattern as an argument and it returns an array if there is match if not it returns null. Let us see how a regular expression pattern looks like. It starts with / sign and ends with / sign.
let string = 'love'
let patternOne = /love/ // with out any flag
let patternTwo = /love/gi // g-means to search in the whole text, i - case insensitive
string.match(substring)
let string = 'I love JavaScript. If you do not love JavaScript what else can you love.'
console.log(string.match('love')) //
let string = "love";
let patternOne = /love/; // with out any flag
let patternTwo = /love/gi; // g-means to search in the whole text, i - case insensitive
string.match(substring);
let stringM =
"I love JavaScript. If you do not love JavaScript what else can you love.";
console.log(stringM.match("love")); //
/*
output
["love", index: 2, input: "I love JavaScript. If you do not love JavaScript what else can you love.", groups: undefined]
*/
let pattern = /love/gi
console.log(string.match(pattern)) // ["love", "love", "love"]
let pattern = /love/gi;
console.log(string.match(pattern)); // ["love", "love", "love"]
// Let us extract numbers from text using regular expression. This is not regular expression section, no panic.
let txt = 'In 2019, I run 30 Days of Python. Now, in 2020 I super exited to start this challenge'
let regEx = /\d/g // d with escape character means d not a normal d instead acts a digit
// + means one or more digit numbers,
let txt =
"In 2019, I run 30 Days of Python. Now, in 2020 I super exited to start this challenge";
let regEx = /\d/g; // d with escape character means d not a normal d instead acts a digit
// + means one or more digit numbers,
// if there is g after that it means global, search everywhere.
console.log(txt.match(regEx)) // ["2", "0", "1", "9", "3", "0", "2", "0", "2", "0"]
console.log(txt.match(/\d+/g)) // ["2019", "30", "2020"]
console.log(txt.match(regEx)); // ["2", "0", "1", "9", "3", "0", "2", "0", "2", "0"]
console.log(txt.match(/\d+/g)); // ["2019", "30", "2020"]

Loading…
Cancel
Save