halenurgurel/goit-js-hw-02
JavaScript Project - Conditions
π§© JavaScript Basics β Homework (Tasks 1β4)
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.
π Project Structure
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
β Homework Tasks Overview
| 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 |
βοΈ Task 1 β Droid Orders
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!
π§ Task 2 β Message Formatting
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..."
π΅οΈββοΈ Task 3 β Spam Check
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
π Task 4 β Shipping Cost (Using Switch)
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"
π§± Concepts Practiced
β Function declaration & parameters
β Conditional statements (if, else, switch)
β String methods (length, slice, toLowerCase, includes)
β Template literals for formatted outputs
β Console-based debugging and testing
π οΈ Tools & Environment
| Tool | Purpose |
|---|---|
| JavaScript (ES6) | Core logic |
| Browser Console | Code execution |
| VS Code | Development |
| GitHub | Version control & submission |
π©βπ» Author
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.β