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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Lab 9 - Starter
# Lab 9 - Starter

## Sherwin Motlagh
330 changes: 225 additions & 105 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,108 +1,228 @@
<!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" />
<title>Lab 9</title>
<script src="https://cdn.trackjs.com/agent/v3/latest/t.js"></script>
<script>
window.TrackJS &&
TrackJS.install({
token: "e0c99ec21c7049538acab79f45111e56",
// for more configuration options, see https://docs.trackjs.com
});
</script>

<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">
<title>Lab 9</title>

<style>
button {
margin: 3px;
}

button:hover {
cursor: pointer;
}

#first-num,
#second-num {
width: 60px;
}

output {
border: 1px solid gray;
display: block;
height: 18px;
margin-top: 5px;
padding: 5px;
width: 240px;
}

main {
width: 800px;
}

#error-btns {
column-gap: 5px;
display: flex;
flex-wrap: wrap;
margin-top: 30px;
row-gap: 5px;
}

#error-btns>* {
padding: 8px 2px;
width: 122px;
}
</style>
</head>

<body>
<main>
<form>
<fieldset>
<legend>Error Calculator</legend>
<input name="first-num" id="first-num" />
<select name="operator" id="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input name="second-num" id="second-num" />
<button id="calculate">Calculate</button>
<br />
<output></output>
</fieldset>
</form>

<section id="error-btns">
<button>Console Log</button>
<button>Console Error</button>
<button>Console Count</button>
<button>Console Warn</button>
<button>Console Assert</button>
<button>Console Clear</button>
<button>Console Dir</button>
<button>Console dirxml</button>
<button>Console Group Start</button>
<button>Console Group End</button>
<button>Console Table</button>
<button>Start Timer</button>
<button>End Timer</button>
<button>Console Trace</button>
<button>Trigger a Global Error</button>
</section>
</main>

<script>
let form = document.querySelector('form');
form.addEventListener('submit', e => {
e.preventDefault();
let output = document.querySelector('output');
let firstNum = document.querySelector('#first-num').value;
let secondNum = document.querySelector('#second-num').value;
let operator = document.querySelector('#operator').value;
output.innerHTML = eval(`${firstNum} ${operator} ${secondNum}`);
});

let errorBtns = Array.from(document.querySelectorAll('#error-btns > button'));

// Start your code here
// You may move this JS to another file if you wish
</script>
</body>

</html>
<style>
button {
margin: 3px;
}

button:hover {
cursor: pointer;
}

#first-num,
#second-num {
width: 60px;
}

output {
border: 1px solid gray;
display: block;
height: 18px;
margin-top: 5px;
padding: 5px;
width: 240px;
}

main {
width: 800px;
}

#error-btns {
column-gap: 5px;
display: flex;
flex-wrap: wrap;
margin-top: 30px;
row-gap: 5px;
}

#error-btns > * {
padding: 8px 2px;
width: 122px;
}
</style>
</head>

<body>
<main>
<form>
<fieldset>
<legend>Error Calculator</legend>
<input name="first-num" id="first-num" />
<select name="operator" id="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input name="second-num" id="second-num" />
<button id="calculate">Calculate</button>
<br />
<output></output>
</fieldset>
</form>

<section id="error-btns">
<button>Console Log</button>
<button>Console Error</button>
<button>Console Count</button>
<button>Console Warn</button>
<button>Console Assert</button>
<button>Console Clear</button>
<button>Console Dir</button>
<button>Console dirxml</button>
<button>Console Group Start</button>
<button>Console Group End</button>
<button>Console Table</button>
<button>Start Timer</button>
<button>End Timer</button>
<button>Console Trace</button>
<button>Trigger a Global Error</button>
</section>
</main>

<script>
try {
form.addEventListener("submit", (e) => {});
} catch (err) {
console.log("Step 3: error handled by catch");
let form = document.querySelector("form");
form.addEventListener("submit", (e) => {
e.preventDefault();
let output = document.querySelector("output");
let firstNum = document.querySelector("#first-num").value;
let secondNum = document.querySelector("#second-num").value;
let operator = document.querySelector("#operator").value;
output.innerHTML = eval(`${firstNum} ${operator} ${secondNum}`);
});
}

let errorBtns = Array.from(
document.querySelectorAll("#error-btns > button")
);

try {
let err_message = "Step 4";
throw err_message;
} catch (err) {
console.error(err);
}

// Start your code here
// You may move this JS to another file if you wish

errorBtns[0].addEventListener("click", () => {
console.log("Console Log");
});

errorBtns[1].addEventListener("click", () => {
console.error("Console Error");
});

errorBtns[2].addEventListener("click", () => {
console.count("Console Count");
});

errorBtns[3].addEventListener("click", () => {
console.warn("Console Warn");
});

errorBtns[4].addEventListener("click", () => {
let x = 5;
let y = 10;
const reply = "y is greater than x";
console.assert(y > x, { x, y, reply });
});

errorBtns[5].onclick = () => {
console.clear();
};

errorBtns[6].addEventListener("click", () => {
console.dir(errorBtns[6]);
});

errorBtns[7].onclick = function () {
console.dirxml(errorBtns[7]);
};

errorBtns[8].addEventListener("click", () => {
console.group();
});

errorBtns[9].addEventListener("click", () => {
console.groupEnd();
});

errorBtns[10].onclick = function () {
console.table([
{
name: "Software Engineering",
num: "110",
},
{
name: "Programming Languages: Principles and Paradigms",
num: "130",
},
{
name: "Computer Security",
num: "127",
},
]);
};

errorBtns[11].onclick = function () {
console.time();
};

errorBtns[12].onclick = function () {
console.timeEnd();
};

errorBtns[13].onclick = function () {
console.trace();
};

errorBtns[14].onclick = function () {
throw new Error("Trigger a Global Error");
};

try {
let obj = document.querySelector("p").value;
console.log(obj);
} catch (err) {
console.error(err);
} finally {
console.log("Last step of the try catch block");
}

class CustomError extends Error {
constructor(message) {
super(message);
this.name = "CustomError";
}
}

try {
throw new CustomError("This is a custom error");
} catch (err) {
console.error(err);
} finally {
console.log("Last step of the try catch block");
}
</script>
</body>
</html>