Task 1:
Task Description:
- Scenario:
You are tasked to simulate a simple shopping experience using conditional statements and loops at a supermarket.
- Requirements:
- Create a TypeScript program that simulates a shopping scenario with multiple conditions.
- Utilize if-else, if-else if-else statements for decision making based on different scenarios encountered while shopping.
- Incorporate nested loops to simulate actions within various sections of the supermarket.
- Functionalities to Include:
- Scenario 1 - Buying Groceries:
- Simulate buying fruits, vegetables, and groceries.
- Apply if-else statements to check specific conditions:
- Check if the customer wants fruits or vegetables.
- Based on the choice, suggest different items available and their prices.
- Display the total bill.
- Scenario 2 - Checking Discounts:
- Introduce a discount scenario based on the total bill amount.
- Use if-else if-else statements to apply discounts:
- If the bill amount is above a certain value, apply a discount.
- Display the discounted total.
- Scenario 3 - Checkout Process:
- Simulate the checkout process.
- Use nested loops to ask for payment methods:
- First, ask the user for the preferred payment method (nested loop for payment options).
- Display a confirmation message based on the payment method chosen.
Task 2:
- Scenario 1: Sum numbers
- Write a function named
add
that takes two numbers as arguments and returns their sum.
- Scenario 2: Check Even or Odd
- Develop a function
checkEvenOrOdd
that checks if a given number is even or odd.
- The function should take an integer as a parameter and return a string indicating whether the number is even or odd.
- Scenario 3: Calculate Area:
- Create a function
calculateArea
that calculates the area of a rectangle.
- The function should take width and height as parameters and return the calculated area.
- Scenario 4: String Reversal
- Implement a function
reverseString
that reverses a given string.
- The function should take a string as a parameter and return the reversed string.
- Scenario 5: Temperature Conversion:
- Create a function
convertCelsiusToFahrenheit
that converts temperature from Celsius to Fahrenheit.
- The function should take a temperature value in Celsius as a parameter and return the equivalent temperature in Fahrenheit.
Task 3:
- Scenario 1 - Modify Array with Methods:
- Initialize an array with some initial elements.
- Demonstrate the usage of the following array methods:
push
: Add new elements to the end of the array.
pop
: Remove the last element from the array.
shift
: Remove the first element from the array.
unshift
: Add new elements to the beginning of the array.
- Scenario 2 - Subarray Creation:
- Implement the use of
splice
and slice
to create subarrays from the original array:
splice
: Create a subarray by removing elements from the original array.
slice
: Create a subarray without modifying the original array.
Guidelines:
- Incorporate comments to explain the logic behind each condition, loop, function or array
- Test your program with various inputs to ensure it responds accurately to different scenarios.
Submission Guidelines:
- Submit the TypeScript file containing your program.
- Include a brief explanation of how your program works and any challenges faced during the implementation.