From 84c2026520f63c8a0d336bdb254f4e84f1f4b860 Mon Sep 17 00:00:00 2001 From: Jose Linardo Date: Tue, 5 Jul 2022 20:05:28 -0500 Subject: [PATCH] web storage day 17 --- 16_Day_JSON/16_day_starter/scripts/main.js | 2 +- .../17_day_starter/scripts/main.js | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/16_Day_JSON/16_day_starter/scripts/main.js b/16_Day_JSON/16_day_starter/scripts/main.js index 7be1bd8..81bae4c 100644 --- a/16_Day_JSON/16_day_starter/scripts/main.js +++ b/16_Day_JSON/16_day_starter/scripts/main.js @@ -154,6 +154,6 @@ for (const element of skillsNum) { let name = txtNames[skillsNum.indexOf(element)] console.log(`${name} ${max}`) } -} // Asab +} // Asab 8 diff --git a/17_Day_Web_storages/17_day_starter/scripts/main.js b/17_Day_Web_storages/17_day_starter/scripts/main.js index e69de29..c9b2f1f 100644 --- a/17_Day_Web_storages/17_day_starter/scripts/main.js +++ b/17_Day_Web_storages/17_day_starter/scripts/main.js @@ -0,0 +1,56 @@ +//Exercises + +//1.Store you first name, last name, age, country, city in your browser localStorage. +localStorage.setItem('firstName', 'Jose') // since the value is string we do not stringify it +console.log(localStorage) + +//Exercises: Level 2 + +//2.Create a student object. The student object will have first name, last name, age, skills, country, enrolled keys and values for the keys. Store the student object in your browser localStorage. +student = { + firstName: 'Juan', + lastName: 'Gomez', + age: 30, + skills: ['HTML', 'CSS', 'JavaScript'], + country: 'Col' +} + +txtStudent = JSON.stringify(student,undefined, 4) +setStorage = localStorage.setItem('student', txtStudent) + +//Exercises: Level 3 + +//1.Create an object 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. +const personAccount = { + + firstName: 'Jane', + lastName: 'Doe', + incomes: { + salary: 5000, + onlinecourses: 15000, + parttime: 1000 + }, + expenses: { + groceries: 1500, + bills: 3000 + }, + + getTotalIncomes(){ + const incomesFrom = Object.keys(this.incomes); + let addIncomes = 0; + for (let i = 0; i < incomesFrom.length; i++){ + addIncomes += this.incomes[incomesFrom[i]] + }; + return addIncomes; + }, + + + + getTotalExpenses () { + const expensesFrom = Object.values(this.expenses); + return expensesFrom.reduce((acc, curr) => acc + curr); + } + + }; + txtPersonAccount = JSON.stringify(personAccount, null, 2) + localStorage.setItem('PersonAccount', txtPersonAccount) \ No newline at end of file