parent
8ad787242b
commit
e368ae9b39
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Level 3 Exercise</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script src="./level3.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -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`)
|
||||||
|
}
|
@ -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.`
|
||||||
|
}
|
@ -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.
|
Loading…
Reference in new issue