forked from in-tech-gration/WDX-180
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>30 Days of JavaScript: JSON exercise</title> | ||
</head> | ||
|
||
<body> | ||
<div class="wrapper"> | ||
</div> | ||
|
||
<script src="./json.js"></script> | ||
|
||
</body> | ||
|
||
</html> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/** | ||
* 30 Days of JavaScript: JSON exercise | ||
* | ||
* Complete the challenges found below! | ||
* */ | ||
|
||
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": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript" | ||
], | ||
"age": 20, | ||
"isLoggedIn": false, | ||
"points": 30 | ||
}, | ||
"Asab": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"Redux", | ||
"MongoDB", | ||
"Express", | ||
"React", | ||
"Node" | ||
], | ||
"age": 25, | ||
"isLoggedIn": false, | ||
"points": 50 | ||
}, | ||
"Brook": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"React", | ||
"Redux" | ||
], | ||
"age": 30, | ||
"isLoggedIn": true, | ||
"points": 50 | ||
}, | ||
"Daniel": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"Python" | ||
], | ||
"age": 20, | ||
"isLoggedIn": false, | ||
"points": 40 | ||
}, | ||
"John": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"React", | ||
"Redux", | ||
"Node.js" | ||
], | ||
"age": 20, | ||
"isLoggedIn": true, | ||
"points": 50 | ||
}, | ||
"Thomas": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"React" | ||
], | ||
"age": 20, | ||
"isLoggedIn": false, | ||
"points": 40 | ||
}, | ||
"Paul": { | ||
"email": "[email protected]", | ||
"skills": [ | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"MongoDB", | ||
"Express", | ||
"React", | ||
"Node" | ||
], | ||
"age": 20, | ||
"isLoggedIn": false, | ||
"points": 40 | ||
} | ||
} | ||
`; | ||
|
||
|
||
/** | ||
* Challenges: | ||
* 1. Change skills array to JSON using JSON.stringify() | ||
* 2. Stringify the age variable | ||
* 3. Stringify the isMarried variable | ||
* 4. Stringify the student object | ||
* 5. Stringify the students object with only firstName, lastName and skills properties | ||
* 6. Parse the *txt* JSON to object. | ||
* 7. Find the user who has many skills from the variable stored in *txt*. | ||
*/ | ||
|
||
// INSERT YOUR CODE BELOW | ||
|
||
const skillsJson = JSON.stringify(skills); | ||
const ageJson = JSON.stringify(age); | ||
const isMarriedJson = JSON.stringify(isMarried); | ||
const studentJson = JSON.stringify(student); | ||
const studentJsonFilter = JSON.stringify(student,['firstName','lastName','skills']); | ||
const txtObj = JSON.parse(txt); | ||
|
||
let maxSkills = 0; | ||
let studentMaxSkills =''; | ||
for (let el in txtObj){ | ||
if (txtObj[el].skills.length > maxSkills){ | ||
maxSkills = txtObj[el].skills.length; | ||
studentMaxSkills = el; | ||
} | ||
} | ||
|
||
console.log('***** Change skills array to JSON using JSON.stringify() ******'); | ||
console.log(skills, skillsJson); | ||
console.log('***** Stringify the age variable ******'); | ||
console.log(age, ageJson); | ||
console.log('***** Stringify the isMarried variable ******'); | ||
console.log(isMarried, isMarriedJson); | ||
console.log('***** Stringify the student object ******'); | ||
console.log(student, studentJson); | ||
console.log('***** Stringify the students object with only firstName, lastName and skills properties ******'); | ||
console.log(studentJsonFilter); | ||
console.log('***** Parse the *txt* JSON to object. ******'); | ||
console.log(txt, txtObj); | ||
console.log('***** Find the user who has many skills from the variable stored in *txt*. ******'); | ||
if (maxSkills) { | ||
console.log(`Student ${studentMaxSkills} have ${maxSkills} skills`); | ||
} else { | ||
console.log ("Students don't have skills"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Week,Day,Concept,Task,Level,Confidence,Completed,Instructions | ||
11,1,Web APIs 2: Asynchronous Programming - Promises - JSON - Fetch API: Introduction to JSON,Read 'Introduction to JSON',Beginner,9,TRUE,Update FALSE to TRUE in the COMPLETED column | ||
11,1,Web APIs 2: Asynchronous Programming - Promises - JSON - Fetch API: Introduction to JSON,Complete the exercise 'JSON Basics',Beginner,8,TRUE,Upload the required assets to the user/week11/exercises/day01/json_basics/ folder |