1

I'm using TextInput boxes for users to put in numbers and for my code to output new numbers but when I go to click the button to make the calculations and output nothing happens. Each box has an instance name and my button is labeled. Can you tell me what the problem may be?

My goal is to mix 2 RGB colors to make a new RBG color. Here is my code:

var r1 = this.r1;
var g1 = this.g1;
var b1 = this.b1;
var r2 = this.r2;
var g2 = this.g2;
var b2 = this.b2;
var r3 = this.r3;
var g3 = this.g3;
var b3 = this.b3;


this.blend_btn.addEventListener("click", Blending);
 
function Blending(evt)
{
    if (r1 >= 0 && r1 <=255)
        {
        r3 = Math.round((r1.text + r2.text)/2);
        r3.text = String(r3);
        }
    if (g1 >= 0 && g1 <=255)
        {
        g3 = Math.round((g1.text + g2.text)/2);
        g3.text = String(g3);
        }
    if (b1 >= 0 && b1 <=255)
        {
        b3 = Math.round((b1.text + b2.text)/2);
        b3.text = String(b3);
        }
}
alea
  • 980
  • 1
  • 13
  • 18
cpez21
  • 11
  • 2
  • Have you tried debugging? – alea May 01 '23 at 06:50
  • How do I do that? Right now, I click test movie and inspect the page, but when I inspect this, no type errors show up – cpez21 May 01 '23 at 07:29
  • see [W3Schools article about Javascript debugging](https://www.w3schools.com/js/js_debugging.asp) about some common ways how to debug javascript applications – alea May 01 '23 at 07:39
  • **Error №1**: you compare TextField to a number. It does not make sense thus does not work in the first place. **Error №2**: you need to learn the difference between the text/string data type and numeric data type. The data inside the input text fields is a string/text, you need to explicitly convert it to a number before you do any math on it. – Organis May 01 '23 at 08:11

0 Answers0