← 全部工具

VuToV-Mykola/goit-js-hw-02

热度 60 更新于 开发与构建

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

githubauto-collected

安装

暂未验证可直接使用的安装命令,请查看项目官方文档或 Release。

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

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