-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript.js
More file actions
27 lines (23 loc) · 1.11 KB
/
JavaScript.js
File metadata and controls
27 lines (23 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function calculate() {
let regexp = /\D/g;
let productPrice = document.getElementsByName("product-price")[0].value;
let productAmount = document.getElementsByName("product-amount")[0].value;
let r = document.getElementById("result");
if (Boolean(productPrice) && Boolean(productAmount)) {
if (regexp.test(productPrice) || regexp.test(productAmount)) {
r.innerText = "Данные введены не корректно";
} else {
regexp = /\d/g;
productPrice = parseInt(productPrice.match(regexp).join(""));
productAmount = parseInt(productAmount.match(regexp).join(""));
r.innerText = `Итоговая цена: ${productPrice * productAmount}`;
}
}else {
r.innerText = "Данные введены не корректно";
}
}
window.document.addEventListener("DOMContentLoaded", function (calculate) {
console.log("DOM is fully loaded and parsed");
let button = document.getElementById("calculate-button");
button.addEventListener("click", calculate);
});