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
Empty file.
69 changes: 69 additions & 0 deletions css/advanced/Assignment-1/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
line-height: 1.6;
}

header {
background: #0d0a99;
color: #fff;
padding: 20px;
text-align: center;
}

nav ul {
list-style: none;
display: flex;
justify-content: center;
gap: 20px;
margin-top: 10px;
}

nav a {
color: #fff;
text-decoration: none;
}

main {
display: flex;
padding: 20px;
gap: 20px;
}

article {
flex: 3;
background: #2c13a8;
color: #fff;
padding: 20px;
border-radius: 8px;
}

aside {
flex: 1;
background: #4d119b;
color: #fff;
padding: 20px;
border-radius: 8px;
}

footer {
background: #3f12ba;
color: #fff;
text-align: center;
padding: 15px;
margin-top: 20px;
bottom: auto;
}

@media (max-width: 768px) {
main {
flex-direction: column;
flex:1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The flex: 1 property here has no effect because its parent element, <body>, does not have display: flex. This line is redundant and can be removed. Also, there should be a space between the property and value for consistency (flex: 1).

Suggested change
flex:1;
flex: 1;

}
}
60 changes: 60 additions & 0 deletions css/advanced/Assignment-2/animations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Animation & Media Queries</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
}
.box {
width: 150px;
height: 150px;
background: #3498db;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-50px);
}
}
@media (max-width: 768px) {
.box {
width: 120px;
height: 120px;
font-size: 14px;
background: #e67e22;
}
}

@media (max-width: 480px) {
.box {
width: 90px;
height: 90px;
font-size: 12px;
background: #2ecc71;
}
}
</style>
Comment on lines +7 to +55
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PR description checklist includes 'Avoid inline styles unless absolutely necessary.' and 'Use modular CSS files if applicable'. Placing CSS within a <style> tag inside an HTML file goes against this best practice. For better maintainability, separation of concerns, and browser caching, these styles should be moved to an external .css file.

</head>
<body>
<div class="box">Hello Guys..!</div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The term 'Guys' is not gender-inclusive. It's a good practice to use neutral language. Consider changing it to 'Everyone' or 'There'.

Suggested change
<div class="box">Hello Guys..!</div>
<div class="box">Hello Everyone..!</div>

</body>
</html>
15 changes: 15 additions & 0 deletions javascript/8-events/Assignment-1/bubbling_delegation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Delegation & Bubbling</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Event Delegation and Bubbling Example</h2>
<table id="myTable"></table>

<script src="script.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions javascript/8-events/Assignment-1/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const table = document.getElementById("myTable");
for (let i = 0; i < 10; i++) {
const row = table.insertRow();
for (let j = 0; j < 10; j++) {
const cell = row.insertCell();
cell.textContent = `${i + 1},${j + 1}`; // Display cell position
}
}
table.addEventListener("mouseover", (event) => {
if (event.target.tagName === "TD") {
const cell = event.target;
const row = cell.parentNode;
const colIndex = cell.cellIndex;

for (let td of row.children) {
td.classList.add("highlight");
}

for (let r of table.rows) {
r.cells[colIndex].classList.add("highlight");
}
}
});

table.addEventListener("mouseout", (event) => {

if (event.target.tagName === "TD") {
for (let row of table.rows) {
for (let cell of row.cells) {
cell.classList.remove("highlight");
}
}
}
});
Comment on lines +26 to +35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The mouseout event handler is inefficient and causes a noticeable flickering effect. It iterates over every cell in the table to remove the highlight class each time the mouse leaves a single cell. A much better approach is to use the mouseleave event on the table element itself. This event fires only once when the mouse pointer moves out of the entire table, allowing you to clear all highlights efficiently.

table.addEventListener("mouseleave", () => {
  for (let row of table.rows) {
    for (let cell of row.cells) {
      cell.classList.remove("highlight");
    }
  }
});

16 changes: 16 additions & 0 deletions javascript/8-events/Assignment-1/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
table {
border-collapse: collapse;
margin: 20px;
}

td {
border: 1px solid black;
padding: 10px;
width: 50px;
text-align: center;
cursor: pointer;
}

.highlight {
background-color: yellow;
}
37 changes: 37 additions & 0 deletions javascript/8-events/Assignment-2/keyboardevents.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Keyboard Events Example</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 40px;
}

.box {
border: 2px solid black;
width: 400px;
margin: 20px auto;
padding: 20px;
font-size: 20px;
min-height: 50px;
}

.keydown {
background-color: lightblue;
}

.keyup {
background-color: lightgreen;
}
</style>
</head>
<body>
<h2>Keyboard Events: Keydown & Keyup</h2>
<div class="box keydown" id="keydownDiv">KeyDown Events:</div>
<div class="box keyup" id="keyupDiv">KeyUp Events:</div>

<script src="script.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions javascript/8-events/Assignment-2/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const keydownDiv = document.getElementById("keydownDiv");
const keyupDiv = document.getElementById("keyupDiv");

let pressedKeys = new Set();


window.addEventListener("keydown", (event) => {
pressedKeys.add(event.key);
const combo = Array.from(pressedKeys).join(" + ");
keydownDiv.textContent = `KeyDown: ${combo}`;
});

window.addEventListener("keyup", (event) => {
pressedKeys.delete(event.key);
keyupDiv.textContent = `KeyUp: ${event.key}`;
});
Comment on lines +13 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The keyup event handler only updates the keyupDiv, leaving the keydownDiv with an outdated state of pressed keys. This can be confusing for the user. To provide accurate feedback, you should update the keydownDiv within the keyup handler as well to reflect the currently pressed keys.

Suggested change
window.addEventListener("keyup", (event) => {
pressedKeys.delete(event.key);
keyupDiv.textContent = `KeyUp: ${event.key}`;
});
window.addEventListener("keyup", (event) => {
pressedKeys.delete(event.key);
const combo = Array.from(pressedKeys).join(" + ");
keydownDiv.textContent = `KeyDown: ${combo}`;
keyupDiv.textContent = `KeyUp: ${event.key}`;
});

23 changes: 23 additions & 0 deletions javascript/8-events/Assignment-3/event_propagation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Event Propagation Example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Event Propagation: Capture, Target, and Bubble</h2>

<div id="level1">
Level 1
<div id="level2">
Level 2
<div id="level3">
Level 3 (Click Me)
</div>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions javascript/8-events/Assignment-3/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const level1 = document.getElementById("level1");
const level2 = document.getElementById("level2");
const level3 = document.getElementById("level3");
level1.addEventListener("click", () => {
alert("Level 1 (Capture Phase)");
}, true);

level2.addEventListener("click", () => {
alert("Level 2 (Bubble Phase)");
});

level3.addEventListener("click", () => {
alert("Level 3 (Target Phase)");
});
Comment on lines +5 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using alert() for demonstration purposes is disruptive because it blocks the UI and halts script execution. For a better user and developer experience, it's recommended to use console.log(). This will output the event propagation sequence to the developer console without interrupting the application flow.

Suggested change
level1.addEventListener("click", () => {
alert("Level 1 (Capture Phase)");
}, true);
level2.addEventListener("click", () => {
alert("Level 2 (Bubble Phase)");
});
level3.addEventListener("click", () => {
alert("Level 3 (Target Phase)");
});
level1.addEventListener("click", () => {
console.log("Level 1 (Capture Phase)");
}, true);
level2.addEventListener("click", () => {
console.log("Level 2 (Bubble Phase)");
});
level3.addEventListener("click", () => {
console.log("Level 3 (Target Phase)");
});

20 changes: 20 additions & 0 deletions javascript/8-events/Assignment-3/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#level1, #level2, #level3 {
padding: 40px;
margin: 10px;
border: 2px solid black;
text-align: center;
font-weight: bold;
cursor: pointer;
}

#level1 {
background-color: #ffd6d6;
}

#level2 {
background-color: #d6ffd6;
}

#level3 {
background-color: #d6d6ff;
}
45 changes: 45 additions & 0 deletions javascript/8-events/Assignment-4/prevent_default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prevent Default Example</title>
<style>
form {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
width: 300px;
border-radius: 10px;
}
input {
display: block;
margin-bottom: 10px;
padding: 8px;
width: 90%;
}
#message {
margin-top: 10px;
font-weight: bold;
color: red;
}
</style>
</head>
<body>

<form id="myForm">
<label>Name:</label>
<input type="text" id="name" placeholder="Enter your name">

<label>Email:</label>
<input type="email" id="email" placeholder="Enter your email">

<button type="submit">Submit</button>
</form>

<p id="message"></p>

<script src="script.js"></script>

</body>
</html>
12 changes: 12 additions & 0 deletions javascript/8-events/Assignment-4/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
document.getElementById("myForm").addEventListener("submit", function(event) {
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const message = document.getElementById("message");
if (name === "" || email === "") {
event.preventDefault();
message.textContent = "Please fill out all fields before submitting!";
} else {
message.style.color = "green";
message.textContent = "Form submitted successfully!";
}
});
Comment on lines +1 to +12
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The form submission is not prevented on success, which causes the page to reload immediately. As a result, the user will never see the 'Form submitted successfully!' message. A better pattern is to call event.preventDefault() at the beginning of the handler and then proceed with validation and displaying the appropriate message.

Suggested change
document.getElementById("myForm").addEventListener("submit", function(event) {
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const message = document.getElementById("message");
if (name === "" || email === "") {
event.preventDefault();
message.textContent = "Please fill out all fields before submitting!";
} else {
message.style.color = "green";
message.textContent = "Form submitted successfully!";
}
});
document.getElementById("myForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent submission to handle it with JS
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const message = document.getElementById("message");
if (name === "" || email === "") {
message.textContent = "Please fill out all fields before submitting!";
} else {
message.style.color = "green";
message.textContent = "Form submitted successfully!";
}
});

12 changes: 12 additions & 0 deletions javascript/8-events/Assignment-5/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

const parentDiv = document.getElementById("parentDiv");
const childDiv = document.getElementById("childDiv");

parentDiv.addEventListener("click", function() {
alert("Parent div clicked!");
});

childDiv.addEventListener("click", function(event) {
alert("Child div clicked!");
event.stopPropagation();
});
Comment on lines +5 to +12
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using alert() is disruptive as it blocks the UI. For demonstrating event behavior, it's better to use console.log(), which logs messages to the developer console without interrupting the user or the application's execution flow.

Suggested change
parentDiv.addEventListener("click", function() {
alert("Parent div clicked!");
});
childDiv.addEventListener("click", function(event) {
alert("Child div clicked!");
event.stopPropagation();
});
parentDiv.addEventListener("click", function() {
console.log("Parent div clicked!");
});
childDiv.addEventListener("click", function(event) {
console.log("Child div clicked!");
event.stopPropagation();
});

Loading