← All tools

VuToV-Mykola/goit-js-hw-02

Popularity 60 Updated Development & Build

📌 GoIT Homework-JS #2: Functions and conditional logic. Four tasks: transaction validation, message formatting, spam detection, and shipping calculator.

githubauto-collected

Installation

A directly usable install command is not verified yet. Check the project documentation or releases.

📸 Скріншот проекту

<!-- END:AUTOGEN --

My Achievements

<!-- --

My Certificates - Completed Sololearn Course:

SOLOLEARN

JavaScript Homework 02

Task 1. Droid Orders

File: task-1.js

The repair droid sales station is ready to go, all that remains is to write the software for the sales department.

Declare the makeTransaction(quantity, pricePerDroid, customerCredits) function, which composes and returns a message about purchasing repair droids.

It declares three parameters, whose values will be set when calling it:

  • quantity — number of ordered droids
  • pricePerDroid — price of one droid
  • customerCredits — amount of funds in the customer's account

Complete the function as follows:

  • Declare a variable to store the total order amount (total cost of all ordered droids) and assign it an expression to calculate this amount.
  • Add a check whether the customer can pay for the order:
  • if the amount to be paid exceeds the number of credits in the customer's account, the function should return the string "Insufficient funds!"
  • otherwise, the function should return the string "You ordered <quantity droids worth <totalPrice credits!", where <quantity is the number of ordered droids, and <totalPrice is their total cost.

Test Code

Add the following code after your function declaration to check its correctness:

console.log(makeTransaction(5, 3000, 23000)); // "You ordered 5 droids worth 15000 credits!"
console.log(makeTransaction(3, 1000, 15000)); // "You ordered 3 droids worth 3000 credits!"
console.log(makeTransaction(10, 5000, 8000)); // "Insufficient funds!"
console.log(makeTransaction(8, 2000, 10000)); // "Insufficient funds!"
console.log(makeTransaction(10, 500, 5000)); // "You ordered 10 droids worth 5000 credits!"