I'm having problems with the resistor color exercise on tcl

I’m working on the resistor color problem but in the requirements there are:

  • to look up the numerical value associated with a particular color band
  • to list the different band colors
    but in the code for test there are other’s like for bl*, for example.

I’m begginer in tcl and I’m not a developer professional my view is very basic for example:

namespace eval resistorColor {
proc colorCode {color} {
set color [string tolower $color]
switch $color {
black { return 0 }
brown { return 1 }
red { return 2 }
orange { return 3 }
yellow { return 4 }
green { return 5 }
blue { return 6 }
violet { return 7 }
grey { return 8 }
white { return 9}
default {
error “Unknown color”
}
}
}

proc colors {} {
    return [list  black brown red orange yellow green blue violet grey white ]
}

}

resistorColor::colors

foreach col [list black brown red orange yellow green blue violet grey white beige bl* ] {
resistorColor::colorCode $col
}

I see other solutions with a array, I belief, but I have to explore them next.

Since you really new to Tcl, you might want to have a look through the tutorial at https://www.tcl-lang.org/doc

Thanks Gleen, I’m reading the tcl tutorial just now. I’m saying that the requirements are incomplete, I belief, because my solution full-fill the two listed but in the test there are other like “beige” and “bl*”.

This post is more for that.

I have to see the other solutions for learn of them.

Thanks again.