Day2-30 Days of Javascript

·

4 min read

//Declare a variable named challenge and assign it to an initial value '30 Days Of JavaScript'.
var challengewithisha = '30 Days of Javascript';
//2.Print the string on the browser console using console.log()
console.log(challengewithisha);
//3.Print the length of the string on the browser console using console.log()
console.log(challengewithisha.length);
//Change all the string characters to capital letters using toUpperCase() method
var upperCaseChallenge = challengewithisha.toUpperCase();
console.log(upperCaseChallenge);
//Change all the string characters to lowercase letters using toLowerCase() method
console.log(challengewithisha.toLowerCase());
//Cut (slice) out the first word of the string using substr() or substring() method
var substtr = challengewithisha.substr(0,2);
console.log("the slice out the first 2 letters",substtr);
//Slice out the phrase Days Of JavaScript from 30 Days Of JavaScript.
var substtr2 = challengewithisha.substr(2,19);
//Check if the string contains a word Script using includes() method
var includeCheck = challengewithisha.includes("Script");
//Split the string into an array using split() method
var splittedString = challengewithisha.split();
console.log(splittedString);
//Split the string 30 Days Of JavaScript at the space using split() method
var splitAtSpace = challengewithisha.split(" ");
//Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' split the string at the comma and change it to an array.
var exampleString2 = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon';
var splitAtComma = exampleString2.split(',');
//12.Change 30 Days Of JavaScript to 30 Days Of Python using replace() method.
var newchallenge = challengewithisha.replace("Javascript","Rust");
//13.What is character at index 15 in '30 Days Of JavaScript' string? Use charAt() method.
challengewithisha.charAt(15);
//What is the character code of J in '30 Days Of JavaScript' string using charCodeAt()
challengewithisha.charCodeAt("J");
//Use indexOf to determine the position of the first occurrence of a in 30 Days Of JavaScript
challengewithisha.indexOf("a");
//Use lastIndexOf to determine the position of the last occurrence of a in 30 Days Of JavaScript.
challengewithisha.lastIndexOf("a");
//Use indexOf to find the position of the first and last occurrence of the word because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
var firstPosition = 'You cannot end a sentence with because because because is a conjunction'
console.log(firstPosition.indexOf("because"));
console.log(firstPosition.lastIndexOf("because"));
//use search to find the position of the first occurance
firstPosition.search("because")
challengewithisha.trim();
//Use startsWith() method with the string 30 Days Of JavaScript and make the result true
//Use endsWith() method with the string 30 Days Of JavaScript and make the result true
challengewithisha.startsWith("30");
challengewithisha.endsWith("Javascript");
var first = "30 Days";
var second = "Of Javascript";
var concatString = concatString.concat(first,second);
console.log(concatString);
//Use repeat() method to print 30 Days Of JavaScript 2 times
challengewithisha.repeat(2);
//The quote 'There is no exercise better for the heart than reaching down and lifting people up.' by John Holmes teaches us to help one another.
console.log('There is no exercise better for the heart than reaching down and lifting people up.')
console.log("Love is not patronizing and charity isn't about pity, it is about love. Charity and love are the same -- with charity you give love, so don't just give money but reach out your hand instead.")
//Check if 'on' is found in both python and jargon
'python'.includes("on") === "Jargon".includes("on")
//I hope this course is not full of jargon. Check if jargon is in the sentence.
var sentence = "I hope this course is not full of jargon";
sentence.includes("jargon");
//Generate a random number between 0 and 100 inclusively.
Math.floor(Math.random()*100)
//Generate a random number between 0 and 255 inclusively.
Math.floor(Math.random()*255)
//Access the 'JavaScript' string characters using a random number.
"Javascript".charAt(Math.floor(Math.random()*"Javascript".length))
//Use console.log() and escape characters to print the following pattern.
console.log("1\t1\t1\t1\t1\n2\t1\t2\t4\t8\n3\t1\t3\t9\t27\n4\t1\t4\t16\t64\n5\t1\t5\t25\t125\n")
//Use substr to slice out the phrase because because because from the following sentence:'You cannot end a sentence with because because because is a conjunction'
var sentence = 'You cannot end a sentence with because because because is a conjunction'
sentence.substr(31,24)
sentence.match(/because/gi);
//Count the number of word love in this sentence.
var loveCount = 'Love is the best thing in this world. Some found their love and some are still looking for their love.' 
loveCount.match(/love/gi);
Clean the following text and find the most frequent word (hint, use replace and regular expressions).
sentence12.replace(/[^a-zA-Z\s]/g,'')
//Calculate the total annual income of the person by extracting the numbers from the following text. 
 var extractNum = 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
sentence2.match(/\d+/g);