lundi 2 janvier 2017

Take value from a previous if statement

I would need to keep the value from the if statement where authorId === 1 and then print it out as another value in the next loop (authorId = 3).

I mean that I need to keep authorSurname.value (id = 1) and print it in the loop (authorId = 3) as the secondAuthor.value because in the loop (authorId = 3) the string authorSurname takes another value.

Can you tell me how can I fix it?

 if (authorId === 0) {
     div.innerHTML = firstAuthorSurname.value + year.value + page.value +
         pageOtherValue;
 } else if (authorId === 1) {
     div.innerHTML = firstAuthorSurname.value + " i " + authorSurname.value +
         " (" + year.value + ")"; 
     var secondAuthorSurname = authorSurname.value;
 } else if (authorId === 2) {
     return secondAuthorSurname;
     div.innerHTML = firstAuthorSurname.value + ", " + secondAuthorSurname.value +
         " and " + authorSurname.value + " (" + year.value + ") " +
         firstAuthorSurname.value + ", " + secondAuthorSurname.value + " and " +
         authorSurname.value + ", " + year.value + ")" + firstAuthorSurname.value +
         ", " + secondAuthorSurname.value + " and " + authorSurname.value +
         ", " + year.value + ") showed that... ";
 }

Aucun commentaire:

Enregistrer un commentaire