This repository contains my JavaScript Basics Homework, which includes four fundamental programming exercises focused on functions, conditions, and logical structures.
Each task was implemented in a separate JavaScript file and tested with console outputs for verification.
js-basics-homework/
│── task-1.js // Droid Orders
│── task-2.js // Message Formatting
│── task-3.js // Spam Detection
│── task-4.js // Shipping Cost (Switch)
│── README.md
| Task | Topic | Description |
|---|---|---|
| Task 1 | Functions & Conditions | Calculate total order cost and check balance |
| Task 2 | String Manipulation | Format text based on maximum length |
| Task 3 | String Search | Detect spam words regardless of case |
| Task 4 | Switch Statement | Return shipping cost or error message |
File: task-1.js
Function: makeTransaction(quantity, pricePerDroid, customerCredits)
Goal: Simulate the purchase process for repair droids. The function should:
Calculate the total cost: quantity * pricePerDroid
Compare with available credits
Return:
-
"Insufficient funds!"
if total > credits -
"You ordered <quantity> droids worth <totalPrice> credits!"otherwise
Example Output:
You ordered 5 droids worth 15000 credits!
File: task-2.js
Function: formatMessage(message, maxLength)
Goal: Ensure the message doesn’t exceed the given character limit.
Logic:
If message length ≤ maxLength, return unchanged
Otherwise, cut it to maxLength characters and add "..."
Example Output:
formatMessage("Curabitur ligula sapien", 16);
// "Curabitur ligula..."
File: task-3.js
Function: checkForSpam(message)
Goal:
Detect forbidden words "spam" or "sale" (case-insensitive).
Logic:
-
Convert message to lowercase using
.toLowerCase() -
Return true if message includes
"spam"or"sale" -
Return false otherwise
Example Output:
checkForSpam("Get best sale offers now!");
// true
File: task-4.js
Function: getShippingCost(country)
Goal: Return the delivery price for the given country using a switch statement.
| Country | Shipping Cost |
|---|---|
| China | 100 credits |
| Chile | 250 credits |
| Australia | 170 credits |
| Jamaica | 120 credits |
If the country isn’t listed:
Return "Sorry, there is no delivery to your country".
Example Output:
getShippingCost("Australia");
// "Shipping to Australia will cost 170 credits"
✅ Function declaration & parameters
✅ Conditional statements (if, else, switch)
✅ String methods (length, slice, toLowerCase, includes)
✅ Template literals for formatted outputs
✅ Console-based debugging and testing
| Tool | Purpose |
|---|---|
| JavaScript (ES6) | Core logic |
| Browser Console | Code execution |
| VS Code | Development |
| GitHub | Version control & submission |
Halenur Gürel
🧠 JavaScript Fundemantals – Homework Submission
📍 Functions · Conditions · Strings · Switch Statements
🔗 GitHub Profile
🎯 “These exercises reinforce essential JavaScript concepts through small but practical coding challenges.”