This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ // This import wouldn't be possible without the allowJS option in tsconfig
2+ import { Formatter } from './format.js' ;
3+
4+ interface Robot {
5+ name : String ,
6+ currentComputation : Number
7+ }
8+
9+ class Robot {
10+ constructor ( public name : String ) {
11+ this . name = name ;
12+ this . currentComputation = 0 ;
13+ }
14+
15+ // Given a mathematical operation, return a value based on the value passed,
16+ // the operation and the number 10
17+ compute ( operation , value ) {
18+ let computedValue = 0 ;
19+ switch ( operation ) {
20+ case '+' :
21+ computedValue = value + 10
22+ case '-' :
23+ computedValue = value - 10
24+ case '/' :
25+ computedValue = value / 10
26+ case '*' :
27+ computedValue = value * 10
28+ }
29+ this . currentComputation = computedValue ;
30+ }
31+
32+ // Using an external JS module, format the computed value from our robot
33+ displayCurrentComputation ( ) {
34+ console . log ( Formatter . surroundWithStars ( this . currentComputation ) ) ;
35+ }
36+ }
37+
38+ const hal = new Robot ( 'Hal' ) ;
39+ hal . compute ( '+' , 32 ) ;
40+ hal . displayCurrentComputation ( ) ;
You can’t perform that action at this time.
0 commit comments