Forum Moderators: open
//eg1 explicit creation of string object
var mystring = new String("doublespeak");
var myid = document.getElementById("results1");
var mypara = document.createElement("p");
var mystr = "The length of variable object myString: " + mystring + " is " + mystring.length + ".";
var mytextnode = document.createTextNode(mystr);
mypara.appendChild(mytextnode);
myid.appendChild(mypara);
//eg2 implicit creation of string object
var myotherstring = "doublethink";
mystr = "The length of variable object myOtherString: " + myotherstring + " is " + myotherstring.length + ".";
mypara = document.createElement("p");
mytextnode = document.createTextNode(mystr);
mypara.appendChild(mytextnode);
myid.appendChild(mypara); var mystring = new String("doublespeak"); var mystring;
mystring = new String("doublespeak");
if I'm appending 50 paragraphs I'm sure I don't need to create 50 unique variable names.
while (conditionistrue){
var mypara = document.createElement("p");
var mytextnode = document.createTextNode("My content model.")
}
I have many for and while loops and I have not used var either
for (var n=0; n<max; n++) {...} while (conditionistrue) {
var mypara = document.createElement("p");
var mytextnode = document.createTextNode("My content model.")
}
var mypara, mytextnode;
while (conditionistrue) {
mypara = document.createElement("p");
mytextnode = document.createTextNode("My content model.")
}
while (conditionistrue) {
var mypara = document.createElement("p");
var mytextnode = document.createTextNode("My content model.")
}
document.createElement("p");
document.createTextNode("My content model.")