Skip to content

About

JavaScript HW-01 — Variables and Data Types, Basics of Functions: Practice declaring variables, working with different data types, and writing simple functions with return values.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

📘 JavaScript Homework 1

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).


🔹 Task 1: Droid Order (task-1.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!`;
}

✅ Test Results

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!"

🔹 Task 2: Product Delivery (task-2.js)

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`;
}

✅ Test Results

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"

🔹 Task 3: Element Width (task-3.js)

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);
}

✅ Test Results

getElementWidth("50px", "8px", "4px") → 74
getElementWidth("60px", "12px", "8.5px") → 101
getElementWidth("200px", "0px", "0px") → 200

📌 Summary & Reflection

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.


📌 Overview

  • Task 1: Droid order calculation
  • Task 2: Shipping cost calculation
  • Task 3: Element width calculation

About

JavaScript HW-01 — Variables and Data Types, Basics of Functions: Practice declaring variables, working with different data types, and writing simple functions with return values.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages