Skip to content

Durga controlstructure js#535

Open
Saidurgasatturi wants to merge 5 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-controlstructure-js
Open

Durga controlstructure js#535
Saidurgasatturi wants to merge 5 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-controlstructure-js

Conversation

@Saidurgasatturi
Copy link
Copy Markdown

@Saidurgasatturi Saidurgasatturi commented Oct 28, 2025

Terms and Conditions

  • I Accept losing points if my PR does not follow the best practices mentioned below, which will impact my overall performance in training

HTML Best Practices

  • File Naming Convention:

  • Follow consistent and descriptive naming (e.g., dashboard.html, user-profile.html).

  • Use lowercase letters and hyphens instead of spaces.

  • Page Title:

  • Ensure the <title> tag is descriptive and aligns with the page content.

  • Include meaningful keywords for SEO if applicable.

  • Semantic Markup:

  • Use appropriate tags like <header>, <footer>, <section>, <article> for better readability and accessibility.

  • Accessibility Standards:

  • Ensure the use of alt attributes for images and proper labels for form elements.

  • Use ARIA roles where necessary.

  • Validation:

  • Ensure the code passes HTML validation tools without errors or warnings.

  • Structure and Indentation:

  • Maintain consistent indentation and proper nesting of tags.

  • Attributes:

  • Ensure all required attributes (e.g., src, href, type, etc.) are correctly used and not left empty.

CSS Best Practices

  • File Organization:

  • Use modular CSS files if applicable (e.g., base.css, layout.css, theme.css).

  • Avoid inline styles unless absolutely necessary.

  • Naming Conventions:

  • Use meaningful class names following BEM or other conventions (e.g., block__element--modifier).

  • Code Reusability:

  • Avoid duplicate code; use classes or mixins for shared styles.

  • Responsive Design:

  • Ensure proper usage of media queries for mobile, tablet, and desktop views.

  • Performance Optimization:

  • Minimize the use of unnecessary CSS selectors.

  • Avoid overly specific selectors and ensure selectors are not overly deep (e.g., avoid #id .class1 .class2 p).

  • Consistency:

  • Follow consistent spacing, indentation, and use of units (rem/em vs. px).

  • Maintain a single coding style (e.g., always use double or single quotes consistently).

Javascript Best Practices

  • File Organization:

  • Ensure scripts are modular and logically separated into files if needed.

  • Avoid mixing inline JavaScript with HTML.

  • Logic Optimization:

  • Check for redundancy and ensure the code is optimized for performance.

  • Avoid unnecessary API calls or DOM manipulations.

  • Solution Approach:

  • Confirm that the code solves the given problem efficiently.

  • Consider scalability for future enhancements.

  • Readability:

  • Use clear variable and function names.

  • Add comments for complex logic or algorithms.

  • Error Handling:

  • Ensure proper error handling for API calls or user input validation.

  • Code Quality:

  • Check for potential bugs (e.g., missing await, mishandling of null/undefined values).

  • Avoid unnecessary console.log statements in production code.

  • Security:

  • Avoid hardcoding sensitive data.

  • Sanitize user input to prevent XSS and other vulnerabilities.

  • Best Practices:

  • Use const and let instead of var.

  • Follow ES6+ standards where applicable.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Saidurgasatturi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the repository's content by introducing a collection of new front-end assignments. The core focus is on practical JavaScript implementations of control structures and various looping mechanisms, demonstrated through 14 interactive web applications. Additionally, it includes foundational CSS examples showcasing responsive design principles and basic animations, providing a well-structured and educational resource for learning web development fundamentals.

Highlights

  • Extensive JavaScript Assignments: Added 14 new JavaScript assignments covering fundamental control structures (if/else, switch) and various loop types (for, while, do-while, for...of, for...in) through practical examples.
  • Interactive Web Tools: Introduced several interactive web applications, including a grading system, leap year checker, simple calculator, largest number finder, odd/even checker, simple interest calculator, multiplication table generator, sum calculator, factorial calculator, array sum/average calculator, character frequency counter, prime number finder, and pyramid pattern generator.
  • Foundational CSS Examples: Included two advanced CSS assignments demonstrating basic layout with flexbox, responsive design using media queries, and CSS animations.
  • Structured Project Organization: Each assignment is self-contained within its own directory, comprising HTML, JavaScript, and CSS files, promoting modularity and ease of understanding.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a comprehensive set of assignments covering various CSS and JavaScript concepts. The code is generally functional, but there are several areas for improvement across all assignments. A recurring issue is the use of inline JavaScript (onclick) and inline CSS (in <style> tags or injected from JS), which goes against the best practices outlined in your PR description. It's highly recommended to separate concerns by moving all styling to CSS files and all script logic, including event handling (using addEventListener), to JavaScript files. Additionally, many of the JavaScript solutions can be made more robust with better input validation and more concise by using modern ES6+ features and built-in methods.

Comment on lines +6 to +16
if (marks >= 90) {
grade = "A";
} else if (marks >= 75 && marks <= 89) {
grade = "B";
} else if (marks >= 50 && marks <= 74) {
grade = "C";
} else if (marks < 50) {
grade = "F";
} else {
grade = "Invalid Input";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The grading logic has a few issues:

  1. Invalid Input Handling: The else block for "Invalid Input" is unreachable for many invalid cases. For example, an empty input is converted to 0 and graded as "F". The logic should explicitly check for empty or non-numeric inputs.
  2. Range Validation: There's no validation for marks outside the typical 0-100 range.
  3. Redundant Conditions: In else if statements like marks >= 75 && marks <= 89, the marks <= 89 part is redundant because the previous if already handled marks >= 90.

These issues can lead to incorrect grades for certain inputs.

Suggested change
if (marks >= 90) {
grade = "A";
} else if (marks >= 75 && marks <= 89) {
grade = "B";
} else if (marks >= 50 && marks <= 74) {
grade = "C";
} else if (marks < 50) {
grade = "F";
} else {
grade = "Invalid Input";
}
if (isNaN(marks) || marks < 0 || marks > 100 || document.getElementById("marks").value.trim() === "") {
grade = "Invalid Input";
} else if (marks >= 90) {
grade = "A";
} else if (marks >= 75) {
grade = "B";
} else if (marks >= 50) {
grade = "C";
} else {
grade = "F";
}


<script src="script.js"></script>
</body>
<
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

There is a stray < character at the end of the file, which makes the HTML invalid and should be removed.

<div class="screenshot">
<h3>Console Output Screenshot:</h3>
<!-- You can replace below image with your own screenshot -->
<img src="screenshot.png" alt="Console Output Screenshot" />
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 <img> tag references screenshot.png, but this file is not included in the pull request. This will result in a broken image icon being displayed on the page.

Comment on lines +5 to +7
if (!year) {
result = "Please enter a valid year!";
}
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 validation if (!year) is buggy. If a user enters 0, Number('0') is 0, and !0 evaluates to true. This incorrectly flags the year 0 as invalid. A more robust check should be used to distinguish between an empty input and a valid input of 0.

Suggested change
if (!year) {
result = "Please enter a valid year!";
}
if (document.getElementById("year").value.trim() === "" || isNaN(year)) {
result = "Please enter a valid year!";
}

Comment on lines +7 to +55
<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>
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 rules are placed inside a <style> block within the HTML file. According to the best practices in the PR description, CSS should be in separate files to avoid mixing it with HTML and to improve maintainability.

Comment on lines +17 to +22
for (let i = 2; i < num; i++) {
if (num % i === 0) {
isPrime = false;
break;
}
}
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 algorithm to check for prime numbers is correct but inefficient. It checks for divisors up to num - 1, but for better performance, you only need to check up to the square root of the number.

Additionally, this logic is repeated inside the main loop. It would be better to extract it into a separate isPrime(num) helper function for improved readability and modularity.

Suggested change
for (let i = 2; i < num; i++) {
if (num % i === 0) {
isPrime = false;
break;
}
}
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
isPrime = false;
break;
}
}

Comment on lines +12 to +23
for (let i = 1; i <= rows; i++) {

for (let space = 1; space <= rows - i; space++) {
pattern += " ";
}

for (let star = 1; star <= 2 * i - 1; star++) {
pattern += "*";
}

pattern += "\n";
}
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 pyramid pattern is built by repeatedly concatenating single characters in loops. While this works, using String.prototype.repeat() can make the code more declarative, concise, and easier to read.

  for (let i = 1; i <= rows; i++) {
    pattern += " ".repeat(rows - i) + "*".repeat(2 * i - 1) + "\n";
  }

Comment on lines +20 to +24
<button onclick="calculate('+')">+</button>
<button onclick="calculate('-')">−</button>
<button onclick="calculate('*')">×</button>
<button onclick="calculate('/')">÷</button>
<button onclick="calculate('%')">%</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.

medium

This file uses inline onclick event handlers. The PR description's best practices state to avoid mixing JavaScript with HTML. It's better to attach event listeners from the script file to separate concerns (structure from behavior).

For example, in your script.js file, you could do:

document.querySelectorAll('.buttons button').forEach(button => {
  button.addEventListener('click', () => calculate(button.textContent));
});

This comment is an example for a recurring issue in many of the HTML files in this PR.

Comment on lines +12 to +18
if (num1 >= num2 && num1 >= num3) {
result = `${num1} is the largest number.`;
} else if (num2 >= num1 && num2 >= num3) {
result = `${num2} is the largest number.`;
} else {
result = `${num3} is the largest number.`;
}
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 code uses a series of if-else if statements to find the largest of three numbers. While correct, JavaScript provides a built-in Math.max() function that is more concise and idiomatic for this purpose.

    const largest = Math.max(num1, num2, num3);
    result = `${largest} is the largest number.`;

}

output += `<h3>Multiplication Table for ${num}</h3>`;
output += "<table style='margin: 0 auto; text-align:left;'>";
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

An inline style (style='...') is being added to the <table> element directly from JavaScript. This violates the best practice of separating structure (HTML), presentation (CSS), and behavior (JS). The styling should be moved to your CSS file.

Suggested change
output += "<table style='margin: 0 auto; text-align:left;'>";
output += "<table class='multiplication-table'>";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant