This repository contains solutions for 3 tasks focused on variables, data types, and basic functions in JavaScript. Each task is implemented in a separate file (task-1.js, task-2.js, task-3.js).
A function that calculates the total cost of droids and returns a formatted message.
function makeTransaction(quantity, pricePerDroid) {
const totalPrice = quantity * pricePerDroid;
return `You ordered ${quantity} droids worth ${totalPrice} credits!`;
}
makeTransaction(5, 3000) → "You ordered 5 droids worth 15000 credits!" makeTransaction(3, 1000) → "You ordered 3 droids worth 3000 credits!" makeTransaction(10, 500) → "You ordered 10 droids worth 5000 credits!"
A function that calculates the total delivery cost (product price + delivery fee) and returns a formatted message.
function getShippingMessage(country, price, deliveryFee) {
const totalPrice = price + deliveryFee;
return `Shipping to ${country} will cost ${totalPrice} credits`;
}
getShippingMessage("Australia", 120, 50) → "Shipping to Australia will cost 170 credits"
getShippingMessage("Germany", 80, 20) → "Shipping to Germany will cost 100 credits"
getShippingMessage("Sweden", 100, 20) → "Shipping to Sweden will cost 120 credits"
A function that calculates the total width of an element (content + padding + border) assuming box-sizing: border-box.
function getElementWidth(content, padding, border) {
return parseFloat(content) + 2 * parseFloat(padding) + 2 * parseFloat(border);
}
getElementWidth("50px", "8px", "4px") → 74
getElementWidth("60px", "12px", "8.5px") → 101
getElementWidth("200px", "0px", "0px") → 200
Great start! 🎉 In Module 1, you learned the fundamentals of JavaScript:
- Declaring and using variables
- Working with different data types: numbers, strings
- Basic string operations (concatenation, template strings)
- How to define and call functions
- Returning values using
return
This module forms the foundation for everything else. Now, with these basics mastered, you’re ready to move on to more complex topics like branching and loops in Module 2.
- Task 1: Droid order calculation
- Task 2: Shipping cost calculation
- Task 3: Element width calculation