Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Calculator_Project_Report.pdf
Binary file not shown.
Binary file added PPT_CALCULATOR.pptx
Binary file not shown.
Binary file added PPT_TODO_LIST.pptx
Binary file not shown.
Binary file added PROJECT.docx
Binary file not shown.
Binary file added ToDo_List_Project_Report.pdf
Binary file not shown.
38 changes: 38 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Calculator</title>
<link rel="stylesheet" href="style.css">
</head>
<body onload="load()">
<div id="calculator">
<!-- Screen and clear key -->
<div class="top">
<span id="clear">C</span>
<div id="screen"></div>
</div>

<div class="keys">
<!-- operators and other keys -->
<span>7</span>
<span>8</span>
<span>9</span>
<span class="operator">+</span>
<span>4</span>
<span>5</span>
<span>6</span>
<span class="operator">-</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span class="operator">÷</span>
<span>0</span>
<span>.</span>
<span class="eval">=</span>
<span class="operator">x</span>
</div>
</div>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
75 changes: 75 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@


function load() {
var btns = document.querySelectorAll("#calculator span");
var operators = ["+", "-", "x", "÷"];
var inputScreen = document.querySelector("#screen");
var btnValue;
var input;

for (var i = 0; i < btns.length; i++) {
var decimalAdded = false; // Flag used to avoid two decimal

btns[i].addEventListener("click", function() {
btnValue = this.innerHTML;
input = inputScreen.innerHTML;

switch (btnValue) {
case "C":
inputScreen.innerHTML = "";
decimalAdded = false;
break;
case "=":
// Last char of string
var lastChar = input[input.length - 1];

// Replace x to *, + to / which could be calculated in eval
input = input.replace(/x/g, "*").replace(/÷/g, "/");

// Checking the last character of the input.
// If it's an operator or a decimal, remove it
// /.$/ means last char in regex
if (operators.indexOf(lastChar) > -1 || lastChar == ".")
input = input.replace(/.$/, "");

if (input) {
// If the argument is an expression, eval() evaluates the expression.
// If the argument is one or more JavaScript statements, eval() executes the statements.
inputScreen.innerHTML = eval(input);
}
decimalAdded = false;
break;
case ".":
if (!decimalAdded) {
inputScreen.innerHTML += btnValue;
decimalAdded = true;
}
break;
case "+":
case "-":
case "x":
case "÷":
// Last char of string
var lastChar = input[input.length - 1];

// Only add operator if input is not empty and there is no operator at the last
if (input != "" && operators.indexOf(lastChar) == -1)
inputScreen.innerHTML += btnValue;
// Allows minus if the string is empty. The first number could be under zero
else if (input == "" && btnValue == "-")
inputScreen.innerHTML += btnValue;

// Allows to represent the last operation
if (operators.indexOf(lastChar) > -1 && input.length > 1) {
inputScreen.innerHTML = input.replace(/.$/, btnValue);
}
decimalAdded = false;
break;
default:
inputScreen.innerHTML += btnValue;
decimalAdded = false;
break;
}
});
}
}
57 changes: 57 additions & 0 deletions index_min.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Caveat&display=swap" rel="stylesheet">
<link href=link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@400;600&display=swap" rel="stylesheet">
<title>TO-DO List</title>
</head>

<body>
<div>
<h1><nobr>Create your own To-Do List!</nobr></h1>
<div class="user-input">
<label for="task">Enter Task :</label>
<input type="text" id="task" placeholder="Let's add something worth doing!">
<button id="addtask">Add to List</button>
<button id="clear" onclick="clearStorage()">Clear List</button>
</div>
<div>
<span class="display">
<h2>Your Items:</h2>
<span class="progress">
<p>Completed: <span id="completed-count">0</span> || Pending: <span id="pending-count">0</span></p>
<!-- <p>Pending: <span id="pending-count">0</span></p> -->
</span>
</span>
<section class="table">
<table>
<thead>
<tr>
<th scope="c">Serial No.</th>
<th scope="c">Task</th>
<th scope="c">Actions</th>
</tr>
</thead>
<tbody id="tablebody">
<tr>
<th scope="r">1</th>
<td>Post this on LinkedIn!</td>
<td class="tbtns"><button>Done</button>
<button>Delete</button></td>
</tr>
</tbody>
</table>
</section class="table">
</div>
<script src="javascript.js"></script>
</body>
</html>
94 changes: 94 additions & 0 deletions javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function getAndUpdate(){
t = document.getElementById('task').value;
if (localStorage.getItem('stringitems')==null){
itemsarray = [];
itemsarray.push([t]);
localStorage.setItem('stringitems', JSON.stringify(itemsarray))
}
else{
stritemsarray = localStorage.getItem('stringitems')
itemsarray = JSON.parse(stritemsarray);
itemsarray.push([t]);
localStorage.setItem('stringitems', JSON.stringify(itemsarray))
}
update()
pendingtasks++;
updatetaskcount();
}

const tasks = document.getElementById("tablebody");
const completedcount = document.getElementById("completed-count");
const pendingcount = document.getElementById("pending-count");

let completedtasks = 0;
let pendingtasks = 0;

function updatetaskcount(){
completedcount.textContent = completedtasks;
pendingcount.textContent = pendingtasks;
}

function update(){
if (localStorage.getItem('stringitems')==null){
itemsarray = [];
localStorage.setItem('stringitems', JSON.stringify(itemsarray))
}
else{
stritemsarray = localStorage.getItem('stringitems')
itemsarray = JSON.parse(stritemsarray);
}
// Populate the table
let tablebody = document.getElementById("tablebody");
let str = "";
itemsarray.forEach((element, index) => {
str += `
<tr>
<th scope="r">${index + 1}</th>
<td>${element[0]}</td>
<td class="tbtns"><button onclick="donetask(${index})">Done</button><button onclick="deletetask(${index})">Delete</button></td>
</tr>`;
});
tablebody.innerHTML = str;
document.getElementById("task").value = "";
}

addtask = document.getElementById("addtask");
addtask.addEventListener("click", getAndUpdate);
update();

function donetask(taskindex){
// console.log("Delete", itemIndex);
stritemsarray = localStorage.getItem('stringitems')
itemsarray = JSON.parse(stritemsarray);
// Delete itemIndex element from the array
itemsarray.splice(taskindex, 1);
localStorage.setItem('stringitems', JSON.stringify(itemsarray));
update();
completedtasks++;
pendingtasks--;
updatetaskcount();
}

function deletetask(taskindex){
// console.log("Delete", itemIndex);
stritemsarray = localStorage.getItem('stringitems')
itemsarray = JSON.parse(stritemsarray);
// Delete itemIndex element from the array
itemsarray.splice(taskindex, 1);
localStorage.setItem('stringitems', JSON.stringify(itemsarray));
update();
pendingtasks--;
updatetaskcount();
}

function clearStorage(){
if (confirm("Do you areally want to clear?"))
{
localStorage.clear();
update()
}
document.getElementById("task").value = "";
completedtasks = 0;
pendingtasks = 0;
updatetaskcount();
}
Loading