I am learning the basics of JavaScript on Coursera in hopes of passing an entrance exam into coding program. I’m VERY new to this and have been cruising along until now. This assignment is on loops and conditionals. The exercise instructions are as follows:
Write code that starts with the image “astrachan.jpg” shown below on the left and replaces the bottom ten rows with black pixels, resulting in the image shown on the right. Note that the color black has a red value of 0, a green value of 0 and a blue value of 0. Also note that the pixel in the top left corner has x-value 0 and y-value 0.
The code below has been started for you. It creates the variable image of type SimpleImage from the image file astrachan.jpg. It then loops over all the pixels replacing only the pixels in the bottom ten rows with black pixels. Then it prints the resulting image. You need to replace the comment // missing code with the missing code.
CODE:
var image = new SimpleImage(“astrachan.jpg”);
// missing code
print(image);
Here is what I have so far but I just get a big black rectangle:
var image = new SimpleImage(“astrachan.jpg”);
for (var pixel of image.values()) {
if (pixel.getX() >= 240);
if (pixel.getY() >= 350);
pixel.setRed(0);
pixel.setGreen(0);
pixel.setBlue(0);
}
print(image);
//I have tried multiple ways and it’s just not clicking. Can someone point me in the correct direction?