-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
javascript-javascript1-week4/juan #125
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
|
||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
|
||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const names = [ | ||
"Peter", | ||
"Ahmad", | ||
"Yana", | ||
"kristina", | ||
"Rasmus", | ||
"Samuel", | ||
"katrine", | ||
"Tala", | ||
]; | ||
const nameToRemove = "Ahmad"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try changing the name to "Yana" and see if it still works :) |
||
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'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
|
||
<script src="script.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
|
||
const travelInformation = { | ||
speed: 50, | ||
destinationDistance: 432, | ||
}; | ||
|
||
|
||
|
||
let horas = travelInformation.destinationDistance / travelInformation.speed; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good. Let's make it a function and check if any variables could be declared const. |
||
|
||
let horasCompletas = Math.floor(horas); | ||
|
||
let minutos = Math.round((horas - horasCompletas) * 60); | ||
|
||
console.log(horasCompletas + " hours and " + minutos + " minutes"); | ||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to make this function and pass the other TV-series objects there as well |
||
|
||
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works, but there's an easier way ;)
Check this out:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find