From e368ae9b39ac7a0bb5a918d09f03b66a7e4607d5 Mon Sep 17 00:00:00 2001 From: Helder Cambuta Date: Tue, 28 Feb 2023 00:11:55 +0100 Subject: [PATCH] :spakles: fix: Resolved issues involving objects (level 1 and level 2) --- .../solutions/conditionals/level3/index.html | 13 +++ .../solutions/conditionals/level3/level3.js | 88 +++++++++++++++ .../solutions/objects/level1/level1.js | 26 +++++ .../solutions/objects/level2/level2.js | 103 ++++++++++++++++++ .../solutions/objects/level3/level3.js | 0 5 files changed, 230 insertions(+) create mode 100644 01_Day_JavaScript_Refresher/solutions/conditionals/level3/index.html create mode 100644 01_Day_JavaScript_Refresher/solutions/conditionals/level3/level3.js create mode 100644 01_Day_JavaScript_Refresher/solutions/objects/level1/level1.js create mode 100644 01_Day_JavaScript_Refresher/solutions/objects/level2/level2.js create mode 100644 01_Day_JavaScript_Refresher/solutions/objects/level3/level3.js diff --git a/01_Day_JavaScript_Refresher/solutions/conditionals/level3/index.html b/01_Day_JavaScript_Refresher/solutions/conditionals/level3/index.html new file mode 100644 index 0000000..d20c70f --- /dev/null +++ b/01_Day_JavaScript_Refresher/solutions/conditionals/level3/index.html @@ -0,0 +1,13 @@ + + + + + + + Level 3 Exercise + + + + + + \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/solutions/conditionals/level3/level3.js b/01_Day_JavaScript_Refresher/solutions/conditionals/level3/level3.js new file mode 100644 index 0000000..5eb9fc7 --- /dev/null +++ b/01_Day_JavaScript_Refresher/solutions/conditionals/level3/level3.js @@ -0,0 +1,88 @@ +/** + * 1. Write a program which tells the number of days in a month. + * */ +const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + +let month = prompt('Enter a month: ') +month = month.toLowerCase() + +if (month == 'january') { + console.log(`January has ${daysInMonth[0]} day`) +} +else if (month == 'february') { + console.log(`February has ${daysInMonth[1]} day`) +} +else if (month == 'march') { + console.log(`March has ${daysInMonth[2]} day`) +} +else if (month == 'april') { + console.log(`April has ${daysInMonth[3]} day`) +} +else if (month == 'may') { + console.log(`May has ${daysInMonth[4]} day`) +} +else if (month == 'june') { + console.log(`June has ${daysInMonth[5]} day`) +} +else if (month == 'july') { + console.log(`July has ${daysInMonth[6]} day`) +} +else if (month == 'august') { + console.log(`August has ${daysInMonth[7]} day`) +} +else if (month == 'september') { + console.log(`September has ${daysInMonth[8]} day`) +} +else if (month == 'october') { + console.log(`October has ${daysInMonth[9]} day`) +} +else if (month == 'november') { + console.log(`November has ${daysInMonth[10]} day`) +} +else if (month == 'december') { + console.log(`December has ${daysInMonth[11]} day`) +} + +/** + * 1.2. Write a program which tells the number of days in a month, + * now consider leap year. + * */ +month = prompt('Enter a month in leap year: ') +month = month.toLowerCase() + +if (month == 'january') { + console.log(`January has ${daysInMonth[0]} day`) +} +else if (month == 'february') { + console.log(`February has ${daysInMonth[1]+1} day`) +} +else if (month == 'march') { + console.log(`March has ${daysInMonth[2]} day`) +} +else if (month == 'april') { + console.log(`April has ${daysInMonth[3]} day`) +} +else if (month == 'may') { + console.log(`May has ${daysInMonth[4]} day`) +} +else if (month == 'june') { + console.log(`June has ${daysInMonth[5]} day`) +} +else if (month == 'july') { + console.log(`July has ${daysInMonth[6]} day`) +} +else if (month == 'august') { + console.log(`August has ${daysInMonth[7]} day`) +} +else if (month == 'september') { + console.log(`September has ${daysInMonth[8]} day`) +} +else if (month == 'october') { + console.log(`October has ${daysInMonth[9]} day`) +} +else if (month == 'november') { + console.log(`November has ${daysInMonth[10]} day`) +} +else if (month == 'december') { + console.log(`December has ${daysInMonth[11]} day`) +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/solutions/objects/level1/level1.js b/01_Day_JavaScript_Refresher/solutions/objects/level1/level1.js new file mode 100644 index 0000000..97cbb06 --- /dev/null +++ b/01_Day_JavaScript_Refresher/solutions/objects/level1/level1.js @@ -0,0 +1,26 @@ +// 1. Create an empty object called dog +const dog = {} + +// 2. Print the the dog object on the console +console.log(dog) + +/** 3. Add name, legs, color, age and bark properties for the dog object. + * The bark property is a method which return woof woof + * */ +dog.name = 'Madara' +dog.leps = 4 +dog.color = 'Black' +dog.age = 1 +dog.bark = function() { + return 'woof woof' +} + +// 4. Get name, legs, color, age and bark value from the dog object +let values = Object.values(dog) + +// 5. Set new properties the dog object: breed, getDogInfo +dog.breed = '' +dog.getDogInfo = function() { + return `Its name is ${this.name}, its is ${this.color}, its is ${this.age} + years old.` +} \ No newline at end of file diff --git a/01_Day_JavaScript_Refresher/solutions/objects/level2/level2.js b/01_Day_JavaScript_Refresher/solutions/objects/level2/level2.js new file mode 100644 index 0000000..0ab9e2a --- /dev/null +++ b/01_Day_JavaScript_Refresher/solutions/objects/level2/level2.js @@ -0,0 +1,103 @@ +const users = { + Alex: { + email: 'alex@alex.com', + skills: ['HTML', 'CSS', 'JavaScript'], + age: 20, + isLoggedIn: false, + points: 30 + }, + Asab: { + email: 'asab@asab.com', + skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'], + age: 25, + isLoggedIn: false, + points: 50 + }, + Brook: { + email: 'daniel@daniel.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'], + age: 30, + isLoggedIn: true, + points: 50 + }, + Daniel: { + email: 'daniel@alex.com', + skills: ['HTML', 'CSS', 'JavaScript', 'Python'], + age: 20, + isLoggedIn: false, + points: 40 + }, + John: { + email: 'john@john.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'], + age: 20, + isLoggedIn: true, + points: 50 + }, + Thomas: { + email: 'thomas@thomas.com', + skills: ['HTML', 'CSS', 'JavaScript', 'React'], + age: 20, + isLoggedIn: false, + points: 40 + }, + Paul: { + email: 'paul@paul.com', + skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'], + age: 20, + isLoggedIn: false, + points: 40 + } +} + +// Find the person who has many skills in the users object. +const userWithMaxSkills = (users) => Object.entries(users) + .reduce((res, [username, data]) => { + console.log(res) + if (data.skills.length > res.maxSkills) { + return { + maxSkills: data.skills.length, + user: { + [username]: data + } + } + } + return res + }, { + maxSkills: -1, + user: undefined + }).user + + +/** + * Count logged in users,count users having greater than equal + * to 50 points from the following object. + * */ +const usersIsLogged = Object.values(users).filter(user => user.isLoggedIn).length +const usersUnderPoints = Object.values(users).filter(user => user.points >= 50).length + +console.log(`User logged: ${usersIsLogged}, users having greater than equal to 50 points ${usersUnderPoints}`) + + +// Find people who are MERN stack developer from the users object +const usersMERNStack = Object.values(users) + .filter(user => user.skills.includes('MongoDB', 'Express', 'React', 'Node')) + + +/** + * Set your name in the users object without modifying the + * original users object + */ +const Nangazaki = Object.assign(users.Asab) +Nangazaki.email = 'heldercambuta44@gmail.com' +Nangazaki.skills = ['HTML', 'CSS', 'JavaScript', 'VueJS', 'TailwindCSS'] +Nangazaki.age = 21 + + +// Get all keys or properties of users object +const keys = Object.keys(users) + +// Get all the values of users object +const values = Object.values(users) + +// Use the countries object to print a country name, capital, populations and languages. diff --git a/01_Day_JavaScript_Refresher/solutions/objects/level3/level3.js b/01_Day_JavaScript_Refresher/solutions/objects/level3/level3.js new file mode 100644 index 0000000..e69de29