This is the code which I have written. The default function should be called when the page loads, without clicking any button. It should display some data and then two buttons should be displayed. What modifications do I need in that code?
I am a beginner so I may have missed many things please help.
This is my JavaScript part, detailed program is given in the link.
function default(){
var i=7;
j=15;
document.write(i+j);
}
Avoid using Keywords
You cannot use the keyword
default:You’ll need to rename your function.
Immediately Invoked Function Expressions
Once you’ve done that, you can wrap it in parenthesis to execute it immediately:
Warning: Avoid
document.writeNote that
document.writewill clear out your document, thus removing the contents of your document. You should instead insert a new text node, or update the contents of an element on the page:You could also add this text node to an element on the page:
This would add the resulting text to any element whose
idattribute isfoo: