0

How can I fix this problem ?

window.onload=function setup(){

    createCanvas(200,200);
}

window.onload=function draw (){
    background(55);
}

I included the javascript file in the html page when I run html page does not show my canvas is there a syntax error ?

Turnip
  • 35,836
  • 15
  • 89
  • 111
Sky Blue
  • 3
  • 3

1 Answers1

1

You can't have two window.onload functions. Every time you assign this property it replaces the previous one. When the page loads, only the last one will be called.

You can combine the functions into one:

window.onload = function() {
    createCanvas(200,200);
    background(55);
};

Or you can use addEventListener to add multiple event listeners.

window.addEventListener("load", function() {
    createCanvas(200, 200);
});
window.addEventListener("load", function() {
    background(55);
});
Barmar
  • 741,623
  • 53
  • 500
  • 612