Skip to content

Commit

Permalink
W11D1 progress updated
Browse files Browse the repository at this point in the history
  • Loading branch information
alkozp committed Dec 18, 2023
1 parent ce1eb3c commit 4b00ea5
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
18 changes: 18 additions & 0 deletions user/week11/exercises/day01/json_basics/json.html
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>
165 changes: 165 additions & 0 deletions user/week11/exercises/day01/json_basics/json.js
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");
}
3 changes: 3 additions & 0 deletions user/week11/progress/progress.w11.d01.csv
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

0 comments on commit 4b00ea5

Please sign in to comment.