class ResistorColor {
private colorOptions: string[]
public colors = {
black: 0,
brown: 1,
red: 2,
orange: 3,
yellow: 4,
green: 5,
blue: 6,
violet: 7,
grey: 8,
white: 9
}
constructor(colorOptions: string[]) {
if( colorOptions.length > 2)
{
for( let key in this.colors)
{
if (this.colors[key].indexOf(colorOptions[0]) !== -1)
{
return key;
}
}
}
this.colorOptions = colorOptions
}
}
The goal is to check if the user-input color exists in the object colors
.
I found inspiration from this discussion on Stack Overflow: Find a value in a JavaScript object
I encountered an error saying cannot find name key
. I am using an online TypeScript editor.
Please help me understand what I am doing incorrectly here.