Fall 2024 - P3
3.1.4 Javascript Hacks
It's your turn to demonstrate your knowledge on variables, finish all the hacks to evaluate your knowledge.
Hack 1: Naming Variables for User Profile
You need to create a user profile using appropriate variable names that reflect the data they hold. The profile includes the user’s full name, age, email, and account balance.
Requirements:
- Use clear, descriptive variable names for full name, age, email, and account balance.
- Assign realistic values to each variable.
- Display the information using
console.log()
in a sentence like:"John Doe, aged 30, can be contacted at johndoe@example.com and has a balance of $1500 in his account."
Hack 2
You’re managing a store’s product inventory. Create some variables that store information about two products, including their names, stock quantities, and prices. Use good naming conventions for each variable.
Requirements:
- Create variables for
productName1
,productPrice1
,productStock1
, and similarly for a second product. - Assign meaningful values to each.
- Output a message that describes each product’s stock and price, such as:
"The store has 10 units of Laptops priced at $1200 each."
Hack 3
Write a program that calculates the total price of an order after tax. Use descriptive variable names to represent item price, quantity, tax rate, and total price after tax.
Requirements:
- Use meaningful variable names (make sure they use camelCase)
- Calculate the total price after tax and store it in totalPriceAfterTax.
- Print out a message like:
"The total price for 3 items each priced at $20 with a tax rate of 10% is $66."