2017-08-10 49 views
-1

我想創建一個代碼框,讓您輸入正確的代碼,然後它會告訴你。修復'預期的表達,得到關鍵字其他'錯誤JavaScript

var code = document.getElementById("codeInsertBox"); 
    var codeText = code.value; 
    if(codeText == "08213"); 
    var newItem = document.createElement("div"); 
    newItem.innerHTML = messageI; 
    document.getElementById("messageAppear").appendChild(newItem); 
    localStorage.setItem('call', '10'); 
    } else { 
    alert("Incorrect Code. Please try again. (If you are seeing this message and the correct code message has appeared, it is an error. Please contact me at [email protected])"); 
    } 
} 

回答

2

你有額外的;後,如果終止如果有馬上和其他成爲孤兒。

當你做;的聲明馬上就結束了。

if(codeText == "08213"); 

等於

if(codeText == "08213"){} 

基本上你的代碼不是if條件內。所以你等於

if(codeText == "08213"){} 
    var newItem = document.createElement("div"); 

刪除那;,你會沒事的。

2

你正在結束if語句。你需要從

if(codeText == "08213"); 

改變你的代碼,以

if(codeText == "08213"){ 

希望一切會正常工作與此有關。

0

刪除;在這一行。

if(codeText == "08213"); 

並正確地格式化您的代碼。

if(codeText == "08213"){ 
     // 
    } else { 
     // 
    }