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 on the main element within this media query is likely not having the intended effect. main is a flex container, not a flex item in a layout where flex: 1 would be meaningful. If the goal is to make the children (article, aside) take up equal space when stacked, you should apply flex properties to them instead. Since they already have flex properties defined, this line is unnecessary and can be removed.

Suggested change
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 CSS styles are currently inside a <style> tag within the HTML file. According to the best practices mentioned in the pull request description, CSS should be in separate files to improve modularity and separation of concerns. Please move these styles to an external CSS file and link it in the <head>.

</head>
<body>
<div class="box">Hello Guys..!</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Manipulation - Assignment 1</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Assignment 1: Accessing and Manipulating Elements</h2>

<table>
<tr>
<th>id</th>
<th>className</th>
<th>tag</th>
<th>name</th>
<th>attribute</th>
</tr>

<tr>
<td>
<p id="para1">Paragraph 1</p>
<p id="para2">Paragraph 2</p>
<button onclick="changeColorById()">Change Color</button>
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

Using onclick attributes directly in the HTML mixes JavaScript logic with your markup. This violates the principle of separation of concerns and makes the code harder to maintain. It's a best practice to attach event listeners from your JavaScript file using addEventListener. You should apply this to all buttons.

Suggested change
<button onclick="changeColorById()">Change Color</button>
<button id="changeColorBtn">Change Color</button>

</td>
<td>
<p class="group">Class Element 1</p>
<p class="group">Class Element 2</p>
<p class="group">Class Element 3</p>
<button onclick="toggleClassColor()">Toggle Background</button>
</td>
<td>
<span>Tag Span 1</span><br>
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 <br> tags to create vertical spacing between elements is not a good practice for layout. CSS should be used for styling and positioning. For example, you can make the <span> elements block-level or use flexbox/grid on their container to control their layout.

Suggested change
<span>Tag Span 1</span><br>
<span>Tag Span 1</span>

<span>Tag Span 2</span><br>
<span>Tag Span 3</span><br>
<button onclick="changeSpanText()">Change Text</button>
</td>
<td>
<input type="text" name="user1" value="Sai"><br>
<input type="text" name="user2" value="Durga"><br>
<input type="text" name="user3" value="Chitti"><br>
<button onclick="toggleDisable()">Toggle Disable</button>
</td>
<td>
<p data-info="custom1">Custom Attribute 1</p>
<p data-info="custom2">Custom Attribute 2</p>
<button onclick="addCustomAttribute()">Add Attribute</button>
</td>
</tr>
</table>
<div id="output"></div>

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

function changeColorById() {
const ids = ["para1", "para2"];
let output = "";
ids.forEach(id => {
const el = document.getElementById(id);
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(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.

high

The random color generation logic can produce invalid hex color codes. toString(16) will not pad with leading zeros, so for smaller numbers, you might get a string shorter than 6 characters (e.g., #fff). This will result in an incorrect color. You should ensure the hex string is always 6 characters long.

Suggested change
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16);
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');

el.style.color = randomColor;
output += `Changed color of ${id} to ${randomColor}<br>`;
});
printResult(output);
}
function toggleClassColor() {
const elements = document.getElementsByClassName("group");
for (let el of elements) {
el.classList.toggle("highlight");
}
printResult("Toggled background color of all elements with class 'group'");
}
function changeSpanText() {
const spans = document.getElementsByTagName("span");
for (let i = 0; i < spans.length; i++) {
spans[i].innerHTML = "Updated Span " + (i + 1);
}
printResult("Updated text content of all <span> elements.");
}
function toggleDisable() {
const inputs = document.querySelectorAll("input[name]");
inputs.forEach(input => {
input.disabled = !input.disabled;
});
printResult("Toggled 'disabled' attribute for all input elements with name attribute.");
}
function addCustomAttribute() {
const element = document.querySelector("[data-info='custom1']");
element.setAttribute("data-added", "newValue");
printResult("Added new attribute: data-added='newValue' to element with data-info='custom1'");
}
function printResult(message) {
document.getElementById("output").innerHTML = message;
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 innerHTML to set content can expose your application to Cross-Site Scripting (XSS) vulnerabilities if the message variable ever contains user-controlled input. While it seems safe in this specific case, it's a best practice to use textContent when you are only setting text. If you need to insert HTML, it's safer to create DOM elements programmatically (e.g., using document.createElement) and append them.

Suggested change
document.getElementById("output").innerHTML = message;
document.getElementById("output").textContent = message;

}
26 changes: 26 additions & 0 deletions javascript/7-dom-manipulation/Assignment-1/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
font-family: Arial, sans-serif;
margin: 20px;
}

table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
text-align: center;
}

h2 {
color: #2a5d84;
}

.highlight {
background-color: lightblue;
}

#output {
margin-top: 20px;
padding: 10px;
border: 1px dashed #555;
background-color: #f5f5f5;
}
22 changes: 22 additions & 0 deletions javascript/7-dom-manipulation/Assignment-10/moving_shadow_dom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Moving Shadow DOM Elements</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Moving Table Rows inside Shadow DOM</h2>

<div id="shadowHost"></div>

<div class="controls">
<button id="upBtn">Move Up</button>
<button id="downBtn">Move Down</button>
<button id="topBtn">Move Top</button>
<button id="bottomBtn">Move Bottom</button>
</div>

<script src="script.js"></script>
</body>
</html>
90 changes: 90 additions & 0 deletions javascript/7-dom-manipulation/Assignment-10/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

const shadowHost = document.getElementById("shadowHost");
const shadowRoot = shadowHost.attachShadow({ mode: "open" });
const shadowHTML = `
<style>
table {
border-collapse: collapse;
width: 100%;
text-align: center;
font-family: Arial;
}
td, th {
border: 1px solid black;
padding: 8px;
}
button {
margin: 2px;
padding: 4px 6px;
}
tr.selected {
background-color: lightyellow;
}
</style>

<table>
<thead>
<tr><th>#</th><th>Item</th><th>Actions</th></tr>
</thead>
<tbody>
${Array.from({ length: 10 }, (_, i) => `
<tr>
<td>${i + 1}</td>
<td>Item ${i + 1}</td>
<td>
<button class="up">Up</button>
<button class="down">Down</button>
<button class="top">Top</button>
<button class="bottom">Bottom</button>
</td>
</tr>
Comment on lines +34 to +40
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 buttons (Up, Down, Top, Bottom) created inside the shadow DOM for each table row are not used. The functionality is handled by buttons outside the shadow DOM that operate on a selectedRow. This can be confusing. To avoid confusion, you should either implement event listeners for these buttons or remove them from the generated HTML.

Suggested change
<td>
<button class="up">Up</button>
<button class="down">Down</button>
<button class="top">Top</button>
<button class="bottom">Bottom</button>
</td>
</tr>
<td></td>

`).join("")}
</tbody>
</table>
`;

shadowRoot.innerHTML = shadowHTML;

const tbody = shadowRoot.querySelector("tbody");
let selectedRow = null;
tbody.addEventListener("click", (e) => {
if (e.target.closest("tr")) {
if (selectedRow) selectedRow.classList.remove("selected");
selectedRow = e.target.closest("tr");
selectedRow.classList.add("selected");
}
});

function moveUp(row) {
const prev = row.previousElementSibling;
if (prev) tbody.insertBefore(row, prev);
}

function moveDown(row) {
const next = row.nextElementSibling;
if (next) tbody.insertBefore(next, row);
}

function moveTop(row) {
tbody.insertBefore(row, tbody.firstElementChild);
}

function moveBottom(row) {
tbody.appendChild(row);
}

document.getElementById("upBtn").addEventListener("click", () => {
if (selectedRow) moveUp(selectedRow);
});

document.getElementById("downBtn").addEventListener("click", () => {
if (selectedRow) moveDown(selectedRow);
});

document.getElementById("topBtn").addEventListener("click", () => {
if (selectedRow) moveTop(selectedRow);
});

document.getElementById("bottomBtn").addEventListener("click", () => {
if (selectedRow) moveBottom(selectedRow);
});
Loading