A collection of JavaScript problem-solving exercises focused on core programming concepts such as input validation, conditional logic, arrays, loops, calculations, and debugging.
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.
- JavaScript (ES6)
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
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
truewhen the elevator is within the safe limit - Returns
falsewhen the weight exceeds the limit
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
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
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
This assignment demonstrates the use of:
- Functions
- Conditional Statements
- Input Validation
- Arrays
- Loops
- Variables
- Mathematical Calculations
- Comparison Operators
typeofArray.isArray()- Debugging
- Problem Solving
This project does not use any external dependencies or packages.
Only core JavaScript is required.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git