-
Notifications
You must be signed in to change notification settings - Fork 0
/
homework4.js
51 lines (50 loc) · 1.47 KB
/
homework4.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function objectNumber() {
var number = prompt("Введите число от 0 до 999", '');
var sum = "";
if (number.length > 3) {
console.log("недопустимое значение");
return sum = null;
} else if (number.length < 3 && number.length > 1) {
var numberTens = number[0];
var numberOnes = number[1];
var numberHundreds = "";
} else if (number.length < 2 && number.length > 0) {
var numberOnes = number[0];
numberTens = "";
numberHundreds = "";
} else if (number.length === 3) {
numberHundreds = number[0];
numberTens = number[1];
numberOnes = number[2];
}
var object = {
hundreds: numberHundreds,
tens: numberTens,
ones: numberOnes,
};
sum = (object.hundreds + object.tens + object.ones);
console.log(sum);
}
// function cartPrice() {
// var sum = 0;
// var cart = {
// Short:{price:500, size:"XL"},
// Jeans:{ price:5000, size:"XL"},
// Sweater: { price:3000, size:"XL"},
// };
// for(item in cart){
sum += cart[item].price;
//
// }
// alert(sum);
// }
function cartPrice() {
var sum = 0;
var cart = {
Short: {price: 500, size: "XL"},
Jeans: {price: 5000, size: "XL"},
Sweater: {price: 3000, size: "XL"},
};
sum = cart.Short.price + cart.Jeans.price + cart.Sweater.price;
alert(sum);
}