From fb974118c5b3f2daa09e97daa1e44a01157a9dd3 Mon Sep 17 00:00:00 2001 From: jemmy Date: Tue, 18 Oct 2022 07:44:08 -1100 Subject: [PATCH] completed day1 & 2 --- 01_Day_Introduction/01_day_starter/main.js | 10 +++- 02_Day_Data_types/02_day_starter/main.js | 68 +++++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/01_Day_Introduction/01_day_starter/main.js b/01_Day_Introduction/01_day_starter/main.js index 2b952bc..5fb006d 100644 --- a/01_Day_Introduction/01_day_starter/main.js +++ b/01_Day_Introduction/01_day_starter/main.js @@ -1,4 +1,8 @@ // the variable values can be accessed from other variable.js file -console.log(firstName, lastName, country, city, age, isMarried) -console.log(gravity, boilingPoint, PI) // 9.81, 100, 3.14 -console.log(name, job, live) \ No newline at end of file +console.log(firstName, lastName, country, city, age, isMarried); +console.log(gravity, boilingPoint, PI); // 9.81, 100, 3.14 +console.log(name, job, live); + +// comments can make code readable +// Welcome to 30DaysOfJavaScript +/* comments can make code readable, easy to reuse and informative */ diff --git a/02_Day_Data_types/02_day_starter/main.js b/02_Day_Data_types/02_day_starter/main.js index 7762908..bd6318a 100644 --- a/02_Day_Data_types/02_day_starter/main.js +++ b/02_Day_Data_types/02_day_starter/main.js @@ -1 +1,67 @@ -// this is your main.js script \ No newline at end of file +// this is your main.js script +// Exercise 1 +const challenge = "30 Days Of Javascript"; +const str1 = "30 Days Of"; +const str2 = " Javascript"; +const companies = "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon"; +const sentence = + "You cannot end a sentence with because because because is a conjunction"; + +console.log(challenge); +console.log(challenge.length); +console.log(challenge.toUpperCase()); +console.log(challenge.substring(0, 2)); +console.log(challenge.slice(3)); +console.log(challenge.includes("script")); +console.log(challenge.split(" ")); +console.log(companies.split(",")); +console.log(challenge.replace("Javascript", "Python")); +console.log(challenge.charAt(15)); +console.log(challenge.charCodeAt("J")); +console.log(challenge.indexOf("a")); +console.log(challenge.lastIndexOf("a")); +console.log(sentence.indexOf("because")); +console.log(sentence.lastIndexOf("because")); +console.log(sentence.search("because")); +console.log(challenge.trim(" ")); +console.log(challenge.startsWith(30)); +console.log(challenge.endsWith("Javascript")); +console.log(challenge.match("a")); +console.log(str1.concat(str2)); +console.log(challenge.repeat(2)); + +// Excercise 2 +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." +); + +let num = "10"; +console.log(typeof 10 === typeof +"10"); +console.log(parseInt(Math.round(+"9.8")) === 10); +console.log("Python".includes("on") && "jargon".includes("on")); +const checkSentence = "I hope this course is not full of jargon."; +console.log(checkSentence.includes("jargon")); +console.log(Math.floor(Math.random() * 101)); +console.log(Math.floor(Math.random() * (100 - 50 + 1) + 50)); +console.log(Math.floor(Math.random() * (255 + 1))); +const js = "JavaScript"; +const random = Math.floor(Math.random() * js.length + 1); +console.log(js.charAt(random), random); +console.log("1 1 1 1 1 \n2 1 2 4 8 \n3 1 3 9 27 \n5 1 5 25 125"); + +const string = `You cannot end a sentence with because because because is a conjunction`; + +console.log(string.substring(30, 54)); + +// Exercise 3 +const loveSentence = + "Love is the best thing in this world. Some found their love and some are still looking for their love."; +console.log(loveSentence.split("love").length); +let pattern = /because/gi; +console.log(string.match(pattern).length); +const sentence3 = + "He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month."; + +const pattern2 = /\d+/g; +const sentenceRegex = sentence3.match(pattern2); +console.log(+sentenceRegex[0] + +sentenceRegex[1] + +sentenceRegex[2]);