File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Document</ title >
6+ </ head >
7+ < body >
8+ < script >
9+ 'use strict'
10+ class Obj {
11+ constructor ( ) {
12+ this . unit = 0
13+ this . tens = 0
14+ this . hunders = 0
15+ }
16+ get vNum ( ) {
17+ return 'hunders:' + this . hunders + '; tens: ' + this . tens + '; unit: ' + this . unit
18+ }
19+ set vNum ( num ) {
20+ if ( Number . isInteger ( num ) && num <= 999 ) {
21+ let str_num = num . toString ( ) ;
22+ for ( let i = 0 ; i < str_num . length ; i ++ ) {
23+ let pos = str_num . length - 1 - i
24+ switch ( i ) {
25+ case 0 : this . unit = parseInt ( str_num . charAt ( pos ) )
26+ break
27+ case 1 : this . tens = parseInt ( str_num . charAt ( pos ) )
28+ break
29+ case 2 : this . hunders = parseInt ( str_num . charAt ( pos ) )
30+ break
31+ }
32+ }
33+ } else {
34+ throw new Error ( "Error , the entered number does not satisfy the conditions" ) ;
35+ }
36+ }
37+ }
38+
39+ let o1 = new Obj
40+ o1 . vNum = 188.1
41+ console . log ( o1 . vNum )
42+ </ script >
43+ </ body >
44+ </ html >
You can’t perform that action at this time.
0 commit comments