JavaScript code to calculate the resistance value of a resistor based on its color bands

Here's an example JavaScript code to calculate the resistance value of a resistor based on its color bands:

const colorCodes = {
  'black': 0,
  'brown': 1,
  'red': 2,
  'orange': 3,
  'yellow': 4,
  'green': 5,
  'blue': 6,
  'violet': 7,
  'gray': 8,
  'white': 9
};

const firstBand = 'brown'; // replace with the actual color of the first band
const secondBand = 'black'; // replace with the actual color of the second band
const thirdBand = 'red'; // replace with the actual color of the third band

const multiplier = 1;
const tolerance = 0.05;

const firstDigit = colorCodes[firstBand];
const secondDigit = colorCodes[secondBand];
const thirdDigit = colorCodes[thirdBand];

const ohms = (firstDigit * 10 + secondDigit) * multiplier;
const ohmsString = ohms.toFixed(2);

console.log(`Resistance value: ${ohmsString} ohms (+/-${tolerance})`);

Related Articles

- All From ChatGPT
PLG_GSPEECH_SPEECH_BLOCK_TITLE