-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask01.html
More file actions
44 lines (43 loc) · 1.36 KB
/
task01.html
File metadata and controls
44 lines (43 loc) · 1.36 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
'use strict'
class Obj{
constructor(){
this.unit = 0
this.tens = 0
this.hunders = 0
}
get vNum(){
return 'hunders:'+this.hunders+'; tens: '+this.tens+'; unit: '+this.unit
}
set vNum(num){
if(Number.isInteger(num) && num <= 999){
let str_num = num.toString();
for(let i=0;i < str_num.length ;i++){
let pos = str_num.length-1-i
switch(i){
case 0: this.unit = parseInt(str_num.charAt(pos))
break
case 1: this.tens = parseInt(str_num.charAt(pos))
break
case 2: this.hunders = parseInt(str_num.charAt(pos))
break
}
}
} else {
throw new Error("Error , the entered number does not satisfy the conditions");
}
}
}
let o1 = new Obj
o1.vNum = 189
console.log(o1.vNum)
</script>
</body>
</html>