Doing an exercise for a course in which I need to change a group of pixels in the top right corner of 2 different images into another color using a function. They gave me part of the code, but I needed to write the body of the function. When I run the code, I get an error from the first print statement saying “Cannot read properties of undefined (reading ‘getString’)”. Can anybody help? Here is the code:
function topRightCorner(cornerWidth, cornerHeight, someImage, red, green, blue) {
for (var pixel of someImage.values()){
if (pixel.getX() >= (someImage.getWidth()- cornerWidth) & pixel.getY() <= cornerHeight){
pixel.setRed(red);
pixel.setGreen(green);
pixel.setBlue(blue);
}
}
}
var picture = new SimpleImage(“chapel.png”);
var result = topRightCorner(30, 60, picture, 255, 255, 0);
print(result);
var picture2 = new SimpleImage(“smalllion.jpg”);
var result2 = topRightCorner(125, 20, picture2, 255, 0, 0);
print(result2);
So I’m very new to this and don’t know what you mean by logging it to the console lol. But the result variable was only created in the line before the print call. It should call the topRightCorner function and assign the values in parentheses to the variables in the function and then execute the code in the function, if that makes sense.
Ok so after I figured out how to look at the console, it is showing the console log line as undefined. So I’m assuming the result variable is undefined, but it should be defined and I don’t understand why it’s not.