To Do List
<!DOCTYPE html>
<html>
<head>
<title>To Do List</title>
<style>
body{
border: 1px solid black;
width: 400px;
height: 400px;
margin: 0 auto;
display: flex;
flex-direction: column;
/* justify-content: center; */
margin-top: 100px;
padding-bottom: 100px;
}
/* .box{
background-color: lightblue;
border: 1px solid red;
width: 400px;
height: 400px;
} */
h1{
text-align: center;
}
input{
width: 200px;
height: 30px;
margin-bottom: 10px;
margin-left: 100px;
}
button{
width: 100px;
height: 30px;
margin-bottom: 10px;
margin-left: 150px;
}
</style>
</head>
<body>
<!-- <div class="box"> -->
<h1>To Do List</h1>
<input id="input">
<br>
<button id="add" onclick="add()">Add</button>
<br>
<ul id="list">
<li>
Hello
<button onclick="deleteItem(event)" >Delete</button>
</li>
</ul>
<!-- </div> -->
<script>
var input = document.getElementById("input");
var ul=document.getElementById("list");
function add(){
var item = document.createElement("li");
item.innerHTML = input.value + "<button onclick='deleteItem(event)'>Delete</button>";
ul.append(item);
}
function deleteItem(event){
event.target.parentElement.remove();
}
</script>
</body>
</html>
Calculator
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<style>
body {
border: 1px solid black;
width: 400px;
height: 400px;
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 100px;
}
h1 {
text-align: center;
}
input {
width: 200px;
height: 30px;
margin-bottom: 10px;
margin-left: 100px;
}
button {
width: 100px;
height: 30px;
margin-bottom: 10px;
margin-left: 150px;
}
p{
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Calculator</h1>
<input id="num1">
<input id="num2">
<br><br>
<button onclick="add()">add</button>
<button onclick="sub()">sub</button>
<button onclick="mul()">mul</button>
<button onclick="div()">div</button>
<p id="result"></p>
<script>
var para = document.getElementById("result");
function add() {
var num1 = Number(document.getElementById("num1").value);
var num2 = Number(document.getElementById("num2").value);
para.innerText = "Result:" + (num1 + num2);
}
function sub() {
var num1 = Number(document.getElementById("num1").value);
var num2 = Number(document.getElementById("num2").value);
para.innerText = "Result:" + (num1 - num2);
}
function mul() {
var num1 = Number(document.getElementById("num1").value);
var num2 = Number(document.getElementById("num2").value);
para.innerText = "Result:" + (num1 * num2);
}
function div() {
var num1 = Number(document.getElementById("num1").value);
var num2 = Number(document.getElementById("num2").value);
para.innerText = "Result:" + (num1 / num2);
// if (num2 === 0) {
// para.innerText = "Cannot divide by zero";
// } else {
// para.innerText = "Result:" + (num1 / num2);
// }
}
</script>
</body>
</html>


Top comments (0)