Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Assignment 02

A collection of JavaScript problem-solving exercises focused on core programming concepts such as input validation, conditional logic, arrays, loops, calculations, and debugging.

📌 Overview

This assignment contains solutions to five different JavaScript problems. Each problem focuses on applying fundamental JavaScript concepts to solve practical programming challenges.

The solutions include proper input validation and return "Invalid" when incorrect input is provided where required.


🛠️ Technologies Used

  • JavaScript (ES6)

📂 Problems & Features

1️⃣ Match Winner

A function that compares the goals of two teams and determines the result.

Features:

  • Validates that both inputs are numbers
  • Compares Team A and Team B goals
  • Returns the winning team
  • Returns "Draw" when both teams have the same score
  • Returns "Invalid" for incorrect input

2️⃣ Elevator Weight Safety Checker

A function that checks whether the total weight inside an elevator is within the allowed safety limit.

Features:

  • Validates that the input is an array
  • Calculates the total weight using a loop
  • Checks the weight against the maximum limit
  • Returns true when the elevator is within the safe limit
  • Returns false when the weight exceeds the limit

3️⃣ AI Token Cost Calculator

A function that calculates the cost of AI token usage.

Features:

  • Validates the token input
  • Handles invalid or negative values
  • Provides the first 500 tokens for free
  • Calculates the remaining chargeable tokens
  • Uses mathematical calculations to determine the total cost

4️⃣ Top Rated Restaurant Finder

A function that finds the restaurant with the highest rating.

Features:

  • Validates that the input is a non-empty array
  • Starts with the first restaurant as the initial highest-rated restaurant
  • Compares restaurant ratings using a loop
  • Updates the top restaurant when a higher rating is found
  • Returns the restaurant name in uppercase

5️⃣ Debugging Challenge – API Response Time Monitor

A debugging-focused function that calculates the average API response time.

Features:

  • Validates that the input is an array
  • Checks for an empty array
  • Ensures all values are numbers
  • Fixes the incorrect loop logic from the buggy code
  • Calculates and returns the average response time

🧠 Concepts Practiced

This assignment demonstrates the use of:

  • Functions
  • Conditional Statements
  • Input Validation
  • Arrays
  • Loops
  • Variables
  • Mathematical Calculations
  • Comparison Operators
  • typeof
  • Array.isArray()
  • Debugging
  • Problem Solving

📦 Dependencies

This project does not use any external dependencies or packages.

Only core JavaScript is required.


🚀 How to Run Locally

1. Clone the repository

git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git

About

A collection of JavaScript problem-solving exercises covering functions, arrays, loops, input validation, calculations, and debugging.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages