File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
exercises/practice/resistor-color-trio/.meta Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 33 " SleeplessByte"
44 ],
55 "contributors" : [
6- " hayashi-ay"
6+ " hayashi-ay" ,
7+ " jagdish-15"
78 ],
89 "files" : {
910 "solution" : [
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const COLORS = [
1212] ;
1313
1414const ONE_KILOOHM = 1000 ;
15+ const ONE_MEGAOHM = 1000000 ;
16+ const ONE_GIGAOHM = 1000000000 ;
1517
1618class ArgumentError extends Error { }
1719
@@ -44,9 +46,18 @@ export class ResistorColorTrio {
4446
4547 toString ( ) {
4648 const value = this . value ;
47- return value < ONE_KILOOHM
48- ? `${ value } ohms`
49- : `${ Math . floor ( value / ONE_KILOOHM ) } kiloohms` ;
49+
50+ if ( value >= ONE_GIGAOHM ) {
51+ return `${ Math . floor ( value / ONE_GIGAOHM ) } gigaohms` ;
52+ }
53+ if ( value >= ONE_MEGAOHM ) {
54+ return `${ Math . floor ( value / ONE_MEGAOHM ) } megaohms` ;
55+ }
56+ if ( value >= ONE_KILOOHM ) {
57+ return `${ Math . floor ( value / ONE_KILOOHM ) } kiloohms` ;
58+ }
59+
60+ return `${ value } ohms` ;
5061 }
5162
5263 /**
You can’t perform that action at this time.
0 commit comments