First I created an id for every empty word that is being filled in. Create a CSS that separates that color of the nouns, the verbs, and the adjectives. Everything was easy until the time when I was trying to loop that array. I knew that I have to use document.getElementById("id").innerHTML = arrN[i], but I really didn't know what is suppose to put in id. I tried ("ni"), (arrN[i]), (ni), and ("arrN[i]"). None of them worked. If I don't use the loop, I would have to write the same line of code so many, many times...
Similar to this but with so much more arrays:
var arrN= [n1, n2];
for (i = 0; i < arrN.length; i++){
arrN[i] = prompt("Enter a noun.");
}
if (n1 != null) {
document.getElementById("n1").innerHTML = arrN[0];
}
if (n2 != null) {
document.getElementById("n2").innerHTML = arrN[1];
}
So I tried reading more online, researching to help myself figure this out at home. Then I finally found what I was look for, and it gave me the idea of what I am suppose to do. I love the moment when you figured the issue of the code that had been bothering you for days! Such an amazing filling! It's one of the best things about coding. I tried it in the Tryit Editor from W3schools, and it worked! I was so happy!
http://www.w3schools.com/code/tryit.asp?filename=FAJEHN5HCBEL
Instead of all of those I've tried, I was suppose to put ("n" + i) in the id.
like this:
var arrN = [];
var i;
for (i = 1; i <= 2 ; i++) {
arrN[i] = prompt("enter");
if(arrN[i] != null){
document.getElementById("n" + i).innerHTML = arrN[i];
}
}
So I applied this to the adjectives and verbs as well and it worked perfectly with some minor adjustments.
I'm just so pround that I had finally figured this out, fully understand it, and be able to apply and use it the way I want it to work.
http://www.w3schools.com/code/tryit.asp?filename=FAJEHN5HCBEL
Instead of all of those I've tried, I was suppose to put ("n" + i) in the id.
like this:
var arrN = [];
var i;
for (i = 1; i <= 2 ; i++) {
arrN[i] = prompt("enter");
if(arrN[i] != null){
document.getElementById("n" + i).innerHTML = arrN[i];
}
}
So I applied this to the adjectives and verbs as well and it worked perfectly with some minor adjustments.
I'm just so pround that I had finally figured this out, fully understand it, and be able to apply and use it the way I want it to work.
https://thimbleprojects.org/jh19tommy2/149052/
No comments:
Post a Comment