My first question here is about implementing the addtodo(todo) code. After trying it out successfully, I wanted to make it work when typing and pressing enter. However, despite attempting some other methods, I couldn't get it to work. I didn't receive any error messages in Chrome or VSCode. As a beginner, my code might be messy. How much more detail do you need? If you don't submit, I'll start writing a story (no kidding).
const dateElement = document.querySelector('.date');
const input = document.querySelector('#text-bar')
const list = document.querySelector('.input')
//date stuff
const options = {
weekday: "long",
month: "short",
day: "numeric"
};
const today = new Date();
dateElement.innerHTML = today.toLocaleDateString("en-US", options);
function toodoo(todo) {
const item =
`
<li><i class="far fa-circle" id="circle"></i></li>
<li>${todo}</li>
<li> <button class="edit">edit</button></li>
<li> <button class="remove">remove</button></li>
`;
const position = "beforeend";
list.insertAdjacentHTML(position, item);
}
document.addEventListener("enter", function(event) {
if (event.keycode == 13) {
const todo = input.Value;
if (todo) {
toodoo(todo);
}
}
});
* {
background-color: coral;
margin: 0px;
}
body {
text-align: center;
margin: 100px;
}
.middle-space {
height: 70vh;
border: 2px solid rgba(126, 125, 125, 0.671);
width: 30%;
margin: auto;
background-color: white;
}
#text-bar {
width: 30%;
border: 2px solid black;
height: 3vh;
margin-left: 25px;
border-radius: 25px;
background-color: white;
}
h1 {
background-image: url('download (1).jpeg');
width: 30%;
padding-top: 8vh;
padding-bottom: 2vh;
text-align: left;
font-size: 25px;
margin: auto;
border: 2px solid rgba(126, 125, 125, 0.671);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-color: white;
}
#button {
color: greenyellow;
font-size: 25px;
}
@media(max-width:600px) {
.middle-space {
width: 100%;
}
#text-bar {
width: 80%;
margin: 0px;
}
h1 {
width: 100%;
}
}
/* Remove Edit */
.input li {
list-style: none;
display: inline;
list-style-type: none;
padding-left: 10px;
background-color: white;
}
.input {
text-align: left;
margin: auto;
background-color: white;
border-bottom: 2px solid black;
border-radius: 24px;
margin-top: 20px;
padding-bottom: 10px;
}
#circle {
background-color: white;
color: greenyellow;
}
ul {
background-color: white;
list-style: none;
}
.edit {
border: none;
background-color: white;
color: green;
margin-left: 150px;
}
.remove {
border: none;
background-color: white;
color: red;
}
.middle-space ul {
padding: 0px;
margin: 0px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
<link rel="stylesheet" href="style.css">
<script src="https://use.fontawesome.com/releases/v5.15.1/js/all.js"></script>
</head>
<body class="body">
<h1 class="date">h</h1>
<div class="middle-space">
<div class="input">
<ul>
<!-- <li><i class="far fa-circle" id="circle"></i></li>
<li>drinkcoffee</li>
<li> <button class="edit">edit</button></li>
<li> <button class="remove">remove</button></li>-->
</ul>
</div>
</div>
<div class="input-field"><input type="text" id="text-bar" placeholder="write stuff or something magic will happen"> <i class="fas fa-plus-circle" id="button"></i></button>
</div>
<script src="test.js"></script>
</body>
</html>