If I were on any other JavaScript editor, the following code would work. However, for whatever reason, certain drawing commands do not work on Codecademy. I’m just curious as to the reason and if there might be a chance that drawing will be implemented in the future on this site.
var Cambria = ("Cambria", 15)
var x = 10;
var y = 25;
noStroke();
textFont(Cambria, 15);
fill(0, 0, 255);
text("Print Page", x, y);
var drawPopUp = function () {
//Pop Up Box
fill(0, 0, 0);
rect(37.5, 100, 325, 175);
//Exit Button
var Button = function(config) {
this.x = config.x || 0;
this.y = config.y || 0;
this.width = config.width || 25;
this.height = config.height || 25;
this.label = config.label || "Click";
};
Button.prototype.draw = function() {
fill(125, 125, 125);
rect(this.x, this.y, this.width, this.height, 5);
fill(255, 255, 255);
var Arial = createFont("Arial",12);
textFont(Arial, 12);
textSize(30);
textAlign(CENTER, CENTER);
text(this.label, this.x+13, this.y+this.height/2.5);
};
Button.prototype.isMouseInside = function() {
return mouseX > this.x &&
mouseX < (this.x + this.width) &&
mouseY > this.y &&
mouseY < (this.y + this.height);
};
var btn1 = new Button({
x: 337.5,
y: 100,
label: "x"
});
btn1.draw();
mouseClicked = function() {
if (btn1.isMouseInside()) {
Program.restart();
}
};
};
var printPage = function () {
mouseClicked = function () {
if (mouseX <= 90) {
if (mouseY <= 30) {
drawPopUp();
fill(255, 255, 255);
textFont(Cambria, 16);
text("This feature has not yet been implemented.", 200, 175);
} else if (mouseY === 30) {
drawPopUp();
fill(255, 255, 255);
textFont(Cambria, 16);
text("This feature has not yet been implemented.", 200, 175);
} else if (mouseY >= 30) {}
else {
drawPopUp();
fill(255, 255, 255);
textFont(Cambria, 30);
text("Error!", 200, 175);
}
} else if (mouseX > 90) {
if (mouseY >= 30) {}
else if (mouseY <= 30) {}
else if (mouseY === 30) {}
else {
drawPopUp();
fill(255, 255, 255);
textFont(Cambria, 30);
text("Error!", 200, 175);
}
} else {
drawPopUp();
fill(255, 255, 255);
textFont(Cambria, 30);
text("Error!", 200, 175);
}
};
};
printPage();
Here is a working example