From 7478ba9c87877eb271be96a454a10d1b5cfba1b4 Mon Sep 17 00:00:00 2001 From: PAINj9 Date: Sat, 7 Dec 2024 20:05:18 +0100 Subject: [PATCH] Homework --- .../week3/NoteTakingApp/index.html | 12 ++ .../javascript1/week3/NoteTakingApp/script.js | 31 ++++ .../week3/VoiceAssistant/index.html | 13 ++ .../week3/VoiceAssistant/script.js | 134 ++++++++++++++++++ .../javascript1/week3/homework/index.html | 13 ++ .../javascript1/week3/homework/script.js | 28 ++++ .../javascript1/week3/homework1/index.html | 13 ++ .../javascript1/week3/homework1/script.js | 22 +++ .../javascript1/week3/homework2/index.html | 11 ++ .../javascript1/week3/homework2/script.js | 46 ++++++ 10 files changed, 323 insertions(+) create mode 100644 javascript/javascript1/week3/NoteTakingApp/index.html create mode 100644 javascript/javascript1/week3/NoteTakingApp/script.js create mode 100644 javascript/javascript1/week3/VoiceAssistant/index.html create mode 100644 javascript/javascript1/week3/VoiceAssistant/script.js create mode 100644 javascript/javascript1/week3/homework/index.html create mode 100644 javascript/javascript1/week3/homework/script.js create mode 100644 javascript/javascript1/week3/homework1/index.html create mode 100644 javascript/javascript1/week3/homework1/script.js create mode 100644 javascript/javascript1/week3/homework2/index.html create mode 100644 javascript/javascript1/week3/homework2/script.js diff --git a/javascript/javascript1/week3/NoteTakingApp/index.html b/javascript/javascript1/week3/NoteTakingApp/index.html new file mode 100644 index 0000000..866d664 --- /dev/null +++ b/javascript/javascript1/week3/NoteTakingApp/index.html @@ -0,0 +1,12 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git a/javascript/javascript1/week3/NoteTakingApp/script.js b/javascript/javascript1/week3/NoteTakingApp/script.js new file mode 100644 index 0000000..a9947cc --- /dev/null +++ b/javascript/javascript1/week3/NoteTakingApp/script.js @@ -0,0 +1,31 @@ +let notes = []; + +function saveNote (content, id) { + // The saveNote function should push an object to the notes array with the keys content and id + notes.push({ + content, + id + }); +} + +function getNote(id) { + for (let i = 0; i < notes.length; i++) { + if (notes[i].id === id) { + return notes[i]; + } + } + return "Error"; +} + +function logOutNotesFormatted() { + for (let i = 0; i < notes.length; i++) { + console.log("The note with id: " + notes[i].id + ", has the following note text: " + notes[i].content); + } +} + +saveNote("Pick up groceries", 1); +saveNote("Do laundry", 2); + +logOutNotesFormatted(); + +console.log(notes); diff --git a/javascript/javascript1/week3/VoiceAssistant/index.html b/javascript/javascript1/week3/VoiceAssistant/index.html new file mode 100644 index 0000000..eb4e8e4 --- /dev/null +++ b/javascript/javascript1/week3/VoiceAssistant/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/javascript/javascript1/week3/VoiceAssistant/script.js b/javascript/javascript1/week3/VoiceAssistant/script.js new file mode 100644 index 0000000..522ad90 --- /dev/null +++ b/javascript/javascript1/week3/VoiceAssistant/script.js @@ -0,0 +1,134 @@ +let userName; +let todos = []; + +function getReply(command) { + + // HELLO MY NAME IS HELLO MY NAME IS + // HELLO MY NAME IS HELLO MY NAME IS + // HELLO MY NAME IS HELLO MY NAME IS + + if (command.includes("Hello my name is")) { + let words = command.split(" "); + userName = words[4]; + return "Nice to meet you " + userName; + } + + // WHAT IS MY NAME WHAT IS MY NAME + // WHAT IS MY NAME WHAT IS MY NAME + // WHAT IS MY NAME WHAT IS MY NAME + + if (command.includes("What is my name")) { + if (userName) { + return "Your name is " + userName; + } else { + return ("I don't know what is your name."); + } + } + + // ADD TASK ADD TASK ADD TASK ADD TASK + // ADD TASK ADD TASK ADD TASK ADD TASK + // ADD TASK ADD TASK ADD TASK ADD TASK + + if (command.includes("Add fishing to my todo")) { + let task = command.split(" ").slice(1, -3).join(" "); + todos.push(task); + + return "Added " + task + " to your todo"; + } + + // DELETE TASK DELETE TASK DELETE TASK + // DELETE TASK DELETE TASK DELETE TASK + // DELETE TASK DELETE TASK DELETE TASK + + if (command.includes("Delete")) { + let task = command.split(" ").slice(1, -3).join(" "); + + if (todos.includes(task)) { + let deleteTask = todos.indexOf(task); + todos.splice(deleteTask, 1); + return "Removed " + task + " from your todo"; + } else { + return "That task is not in the list"; + } + } + + // CHECK TO DO CHECK TO DO CHECK TO DO + // CHECK TO DO CHECK TO DO CHECK TO DO + // CHECK TO DO CHECK TO DO CHECK TO DO + + if (command.includes("What is on my todo?")) { + if (todos.length > 0) { + return "You have " + todos.length + " tasks: " + todos.join(", "); + } else { + return "You have no tasks yet"; + } + } + + // DATE DATE DATE DATE DATE DATE + // DATE DATE DATE DATE DATE DATE + // DATE DATE DATE DATE DATE DATE + + if (command.includes("What day is it today?")) { + const nameDays = [ + "January", "February", "March", "April", "May", "June", "July", "August", + "September", "October", "November", "December" + ]; + + let today = new Date(); + let todayDate = today.getDate(); + let todayMonth = today.getMonth(); + let todayYear = today.getFullYear(); + + let monthName = nameDays[todayMonth]; + + return ("Today is " + todayDate + " of " + monthName + " of " + todayYear); + } + + // OPERATIONS OPERATIONS OPERATIONS + // OPERATIONS OPERATIONS OPERATIONS + // OPERATIONS OPERATIONS OPERATIONS + + let parts = command.split(" "); + let num1 = parseFloat(parts[0]); + let num2 = parseFloat(parts[2]); + let operator = parts[1]; + + if (operator === "+") { + return num1 + num2; + } else if (operator === "-") { + return num1 - num2; + } else if (operator === "*") { + return num1 * num2; + } else if (operator === "/") { + return num1 / num2; + } else if (operator === "%") { + return num1 % num2; + } else { + return "What is that operator?"; + } + + // TIMER TIMER TIMER TIMER TIMER + // TIMER TIMER TIMER TIMER TIMER + // TIMER TIMER TIMER TIMER TIMER + + if (command.includes("Set a timer for")) { + let words = command.split(" "); + let timer = words[4]; + let timeLeft = parseInt(timer) * 60000; + + setTimeout(() => { + console.log("Timer Done"); + }, timeLeft); + + return "Timer set for " + timer + " minutes."; + } +} + +// Para probar las respuestas +console.log(getReply("Hello my name is Benjamin")); +console.log(getReply("What is my name")); +console.log(getReply("Add fishing to my todo")); +console.log(getReply("What is on my todo?")); +console.log(getReply("What day is it today?")); +console.log(getReply("What is 3 + 3")); +console.log(getReply("Set a timer for 4")); diff --git a/javascript/javascript1/week3/homework/index.html b/javascript/javascript1/week3/homework/index.html new file mode 100644 index 0000000..66fc074 --- /dev/null +++ b/javascript/javascript1/week3/homework/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/javascript/javascript1/week3/homework/script.js b/javascript/javascript1/week3/homework/script.js new file mode 100644 index 0000000..c2a96d7 --- /dev/null +++ b/javascript/javascript1/week3/homework/script.js @@ -0,0 +1,28 @@ +const names = [ + "Peter", + "Ahmad", + "Yana", + "kristina", + "Rasmus", + "Samuel", + "katrine", + "Tala", + ]; + const nameToRemove = "Ahmad"; + const borrar = names.indexOf(nameToRemove); + + + // Write some code here + + if (names.includes(nameToRemove)) { + + names.splice(borrar, borrar); + + } + + + + // Code done + + + console.table(names); // ['Peter', 'Yana', 'kristina', 'Rasmus', 'Samuel', 'katrine', 'Tala'] \ No newline at end of file diff --git a/javascript/javascript1/week3/homework1/index.html b/javascript/javascript1/week3/homework1/index.html new file mode 100644 index 0000000..66fc074 --- /dev/null +++ b/javascript/javascript1/week3/homework1/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/javascript/javascript1/week3/homework1/script.js b/javascript/javascript1/week3/homework1/script.js new file mode 100644 index 0000000..db8b477 --- /dev/null +++ b/javascript/javascript1/week3/homework1/script.js @@ -0,0 +1,22 @@ + + +const travelInformation = { + speed: 50, + destinationDistance: 432, + }; + + + +let horas = travelInformation.destinationDistance / travelInformation.speed; + +let horasCompletas = Math.floor(horas); + +let minutos = Math.round((horas - horasCompletas) * 60); + +console.log(horasCompletas + " hours and " + minutos + " minutes"); + + + + + + diff --git a/javascript/javascript1/week3/homework2/index.html b/javascript/javascript1/week3/homework2/index.html new file mode 100644 index 0000000..5c92a67 --- /dev/null +++ b/javascript/javascript1/week3/homework2/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file diff --git a/javascript/javascript1/week3/homework2/script.js b/javascript/javascript1/week3/homework2/script.js new file mode 100644 index 0000000..3b33824 --- /dev/null +++ b/javascript/javascript1/week3/homework2/script.js @@ -0,0 +1,46 @@ + +// SERIE DURATION + +const seriesDurations = [ + { + title: "Breaking Bad", + days: 2, + hours: 3, + minutes: 40, + } + ]; + +// CALCULATING TIME OF SERIES IN HOURS + + + const totalHoras = (seriesDurations[0].days * 24) + seriesDurations[0].hours + (seriesDurations[0].minutes / 60); + +// CREATING ARRAY + OBJECT WITH MY INFO + + + const lifeTime = [ { + nombre: "Juan", + days: 8760, + }, + ]; + +// TRANSFORMING MY DAYS INTO HOURS + + const lifeHours = (lifeTime[0].days * 24); + + +// CALCULATING PERCENTAGE OF SEEN SERIES + + const percentage = (totalHoras / lifeHours).toFixed(5) * 100; + + + + console.log("The total ammount of lived hours of " + lifeTime[0].nombre + " is " + lifeHours); + console.log("The total ammount of watched hours are: " + totalHoras); + console.log("The percentage of your life that you spend watching series is " + percentage + "%") + + +// I learn that ".toFixed(5)" limited the ammount of numbers of decimals that are shows +// I learn that ".toFixed(5)" limited the ammount of numbers of decimals that are shows +// I learn that ".toFixed(5)" limited the ammount of numbers of decimals that are shows +// I learn that ".toFixed(5)" limited the ammount of numbers of decimals that are shows \ No newline at end of file