2.10 Coding Challenge-2: Calculate Grade Average

4 min read

This tutorial revises JavaScript concepts: strings and template literals which enhance string readability, and if/else conditional statements controlling program flow. It presents a coding challenge to calculate and compare two students’ average grades, using variables, calculations, and if/else statements effectively. It emphasizes understanding of basic programming constructs, problem-solving abilities and decision-making in coding.

Revision Tutorial: Strings and Template Literals

In JavaScript, strings are sequences of characters enclosed in single (' ') or double (" ") quotes. Template literals provide a convenient way to embed expressions within strings, enhancing readability and flexibility. Example of a string:

let greeting = 'Hello, World!';
let name = 'Amit';
let greetingMessage = Welcome, ${name}!;
console.log(greetingMessage); // Output: Welcome, Amit!

Template literals use backticks (``) and allow the inclusion of variables or expressions using the ${} syntax.

Revision Tutorial: if/else Statements

The if/else statement is fundamental in programming and helps make decisions based on conditions. It follows this structure:

if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false


let age = 20;

if (age >= 18) {
console.log('You are eligible for voting.');
} else {
console.log('You are not eligible for voting yet.');

Ensure you grasp the logic of conditions, as they are pivotal in controlling the flow of your program. Take time to understand how if/else statements can be used to create powerful and dynamic code structures.

Feel confident with these concepts? Great! Now, let’s apply them in a coding challenge to calculate and compare average grades.

Coding Challenge

Calculate Grade Average

You are tasked with writing a program to calculate and compare the average grades of two students, Aditya and Ayush.

Your tasks:

  1. Store the grades of Aditya and Ayush in variables.
  2. Calculate the average grade for each student.
  3. Create a Boolean variable ‘adityaHigherAverage‘ containing information about whether Aditya has a higher average grade than Ayush.
  4. Print a clear and informative output to the console, indicating whose average grade is higher. Use a template literal to include the average grade values in the output. For example: “Aditya's average grade (87.5) is higher than Ayush's (75.2)!
ALSO READ:  1.4 Inline JavaScript

Test data:

  • Data 1: Aditya’s grades are 90, 85, 92, and 80. Ayush’s grades are 78, 80, 72, and 81.
  • Data 2: Aditya’s grades are 88, 94, 89, and 92. Ayush’s grades are 85, 87, 90, and 88.
  • Data 3: Aditya’s grades are 75, 82, 79, and 88. Ayush’s grades are 80, 76, 85, and 72.
  • Data 4: Print the average grade-related information using if/else statements.

Hint: Utilize an if/else statement to compare the average grades and structure your output accordingly.

Challenge Yourself: Mastering Grade Averages

Embark on this coding challenge to strengthen your skills in handling variables, performing calculations, and using if/else statements effectively. By comparing the average grades of two students, Aditya and Ayush, you’ll gain valuable insights into conditional statements and template literals.

This challenge provides a practical opportunity to reinforce your understanding of basic programming constructs while tackling a real-world scenario. Enhance your problem-solving abilities as you navigate through the given test data, calculate averages, and determine which student outshines the other academically.

As you conquer this challenge, you’ll not only sharpen your coding skills but also develop a deeper appreciation for the logical reasoning and decision-making aspects of programming. So, dive in, apply your knowledge, and level up your proficiency in JavaScript programming!

Submitting Your Challenge:

Once you’ve completed the coding challenge, follow these steps to submit your solution:

  1. Comment Section: Look for the comment section.
  2. Paste Your Code: Copy your entire solution and paste it into the comment box. Make sure to include comments if you think they enhance the clarity of your code.
  3. Reflect on Your Solution: Briefly share your thought process or any challenges you faced. This helps in understanding your approach.
  4. Seek Feedback (Optional): If you’d like feedback on your solution, explicitly mention it in your comment. Others in the community may provide valuable insights.
  5. Engage with Others: Take some time to read and engage with comments from fellow learners. Learning from diverse solutions and perspectives is a valuable part of the process.
ALSO READ:  2.5 Basic Operators in JavaScript

Remember, the goal is to learn and grow. Everyone has a unique approach, and sharing yours contributes to a collaborative learning environment.

Best of luck, and enjoy the learning journey!

Avatar for Amit

Amit (16)

Hello! I'm Amit Kumar, a passionate teacher specializing in web development and digital marketing. With several years of experience in the industry, I am dedicated to sharing my knowledge and expertise to empower aspiring learners like you.

Teaching Philosophy:

I believe in creating a dynamic and engaging learning environment where students can thrive. My teaching approach focuses on hands-on experience, practical applications, and real-world examples. I strive to make complex concepts understandable and enjoyable, ensuring that you not only grasp the fundamentals but also develop the skills necessary to excel in web development and digital marketing.

Web Development Expertise:

As a web development instructor, I am well-versed in HTML, CSS, JavaScript, and various frameworks such as React and Angular. I will guide you through the process of building responsive and user-friendly websites, exploring topics like front-end development, back-end integration, database management, and more. Together, we will delve into the latest trends and best practices in web development, equipping you with the tools to create stunning online experiences.

Digital Marketing Mastery:

In the rapidly evolving digital landscape, digital marketing is crucial for businesses to thrive. Through my digital marketing courses, I will help you navigate the intricacies of search engine optimization (SEO), social media marketing, content strategy, email marketing, and analytics. Gain insights into effective marketing techniques, harness the power of data-driven decision-making, and learn how to craft compelling campaigns that drive results.

ALSO READ:  2.4 Variable Declarations: let, const, and var

Passion for Teaching:

Teaching is not just a profession for me; it's my passion. I find great joy in witnessing my students grow and succeed. I am committed to fostering a supportive learning community where questions are encouraged, ideas are shared, and challenges are overcome together. I am here to guide you every step of the way and provide the necessary resources for your personal and professional development.

Join me on this exciting journey of learning and discovery. Let's unlock your potential in web development and digital marketing together. Enroll in my courses today and embark on a transformative educational experience that will propel your career forward.
Start Learning Today!

5 1 vote
Article Rating
Notify of


Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Scroll to Top