Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Why it turns out that "pix1 is not defined"?

My code is going like this:

function printPixel(nameImage, xpos, ypos) {
    var someImg = new SimpleImage(nameImage);
    var pix1 = someImg.getPixel(xpos,ypos);
    return pix1.getRed();
}
console.log(pix1)

printPixel("drewgreen.png",10, 10);
printPixel("drewgreen.png",250, 500);

The output always tells me that "pix1 is not defined", could you help me with my code? P.S: I edit the code in an online interpreter and the pngs have been uploaded already

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I solved the problem by the code following:

function printPixel(nameImage, xpos, ypos) {
    var someImage = new SimpleImage(nameImage) ;
    print("red is " + someImage.getRed(xpos,ypos));
    print("green is " + someImage.getGreen(xpos,ypos));
    print("blue is " + someImage.getBlue(xpos,ypos));
}
printPixel("drewgreen.png",10, 10);
printPixel("drewgreen.png",250, 500);

and here is another same question that I don't know why it goes like this:

function sumPixel(nameOfImage, xpos, ypos) {
    var theImage = new SimpleImage(nameOfImage) ;
    var redNumber = theImage.getRed(xpos,ypos);
    var blueNumber = theImage.getBlue(xpos,ypos);
    var greenNumber = theImage.getGreen(xpos,ypos);
    return redNumber + blueNumber + greenNumber;
}
sumPixel("drewgreen.png",10, 10);
sumPixel("drewgreen.png",250, 500);

It turns out the same thing: nothing was displayed, anyone can help me with this?

about 4 years ago · Juan Pablo Isaza Report

0

OK, I solved the second problem again by myself, just paste it here to mark it or share with you guys:

function sumPixel(nameOfImage, xpos, ypos) {
    var theImage = new SimpleImage(nameOfImage) ;
    var redNumber = theImage.getRed(xpos,ypos);
    var blueNumber = theImage.getBlue(xpos,ypos);
    var greenNumber = theImage.getGreen(xpos,ypos);
    return redNumber + blueNumber + greenNumber;
}

var answer = sumPixel("drewgreen.png", 250, 500);
print(answer);
answer = sumPixel("drewgreen.png",10, 10);
print(answer);

I found both of the two problems is related to lack of print. No print order, so it show nothing.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!