day 16 JSON Done

pull/387/head
Jose Linardo 3 years ago
parent cad9943764
commit b8f33e9e8f

@ -184,7 +184,7 @@ class Statistics {
let statistics = new Statistics()
console.log(statistics.mean(ages), statistics.median(ages), statistics.mode(ages))
//2.Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has totalIncome, totalExpense, accountInfo,addIncome, addExpense and accountBalance methods. Incomes is a set of incomes and its description and expenses is also a set of expenses and its description.
ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
class PersonAccount {
constructor(firstName, lastName, incomes, expenses) {

@ -1,2 +1,159 @@
console.log(countries)
alert('Open the console and check if the countries has been loaded')
//alert('Open the console and check if the countries has been loaded')
//Exercises Level 1
//1. Change skills array to JSON using JSON.stringify()
const skills = ['HTML', 'CSS', 'JS', 'React','Node', 'Python']
let age = 250;
let isMarried = true
const student = {
firstName:'Asabeneh',
lastName:'Yetayehe',
age:250,
isMarried:true,
skills:['HTML', 'CSS', 'JS', 'React','Node', 'Python', ]
}
const txt = `{
"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
}
}
`
let txtSkills = JSON.stringify(skills)
console.log(txtSkills) //["HTML","CSS","JS","React","Node","Python"]
//2. Stringify the age variable
let ageTxt = JSON.stringify(age)
console.log(ageTxt)
//3. Stringify the isMarried variable
isMarriedTxt = JSON.stringify(isMarried)
console.log(isMarriedTxt)
//4. Stringify the student object
let studentTxt = JSON.stringify(student)
console.log(student)
//Exercises Level 2
//1. Stringify the students object with only firstName, lastName and skills properties
let studentObject = JSON.stringify(student, ["firstName", "lastName", "skills"], 2)
console.log(studentObject,)
// Exercises Level 3
//1. parse the txt JSON to object
txtObject = JSON.parse(txt)
console.log(txtObject)
//2. Find the user who has many skills from the variable stored in txt.
const txtNames = Object.keys(txtObject);
console.log(txtNames)
const skillsNum = [];
for (let i = 0; i < txtNames.length; i++) {
skillsNum.push(txtObject[`${txtNames[i]}`].skills.length);
}
let max = Math.max(...skillsNum);
console.log(skillsNum)
for (const element of skillsNum) {
if (element === max) {
let name = txtNames[skillsNum.indexOf(element)]
console.log(`${name} ${max}`)
}
} // Asab

Loading…
Cancel
Save