vendredi 14 juin 2019

Unexpected Token Else, not seeing syntax error in code

I'm writing an if else statement, and getting a prompt for an unexpected token else. I've had this problem a few times before, and in result of never finding an answer I've just resorted to NEVER using else. Only else if. Any help would be greatly appreciated.

if (stringList.length == 1){

    let pairToPush = `${stringList[0]}_`
    answerList.push(pairToPush)

  } else if (stringList.length % 2 == 0){

    for (let i = 0; i < stringList.length; i + 2){
      let pairToPush = `${stringList[i]}${stringList[i+1]}`
      answerList.push(pairToPush);

  } else {

    for (let i = 0; i < stringList.length; i++){
      if (i == 0 || i % 2 == 0){
        let pairToPush = `${stringList[i]}${stringList[i+1]}`
        answerList.push(pairToPush);
      } else if (i == (stringList.length - 1)){
        let pairToPush = `${stringList[i]}_`
        answerList.push(pairToPush)

Aucun commentaire:

Enregistrer un commentaire