+ 1
Help plz. Why 1st work,2nd not. What's the problem?
1st: function sayHello(name, age) { document.write( name + " is " + age + " years old."); } sayHello("John", 20); 2nd: function sayHello(name, age) { document.getElementById("show").innerHTML=( name + " is " + age + " years old."); } sayHello("John", 20);
2 Antworten
+ 3
In Sololearn script it linked in head tag so it's likely that your html elements are not loaded, so you have to wait for it to load before calling that Javascript function.
You have to use window.onload property.
function sayHello(name, age) {
document.getElementById("show").innerHTML=( name + " is " + age + " years old.");
}
window.onload = function() {
sayHello("John", 20);
}
+ 1
Thanks 🔫 Rick Grimes