2017-08-12 65 views
0
var user = window.prompt("Welcome to the Vacation Planner. Please enter yourname"); 
document.getElementById("greeting").innerHTML += ", " + user; 
var enterDays = document.getElementById("enterDays"); 
/* 
function.calculateDays(){ 
    var dayMessage = document.getElementById("dayMessage"); 
    if(enterDays <4){ 
     dayMessage.innerHTML = "Short trips are always worth it!"; 
     } 
    else if(enterDays<7){ 
     dayMessage.innerHTML = "Cool, you'll be there for a week" 
     } 
    else{ 
     dayMessage.innerHTML = "You'll have plenty of time to relax and have fun!" 
     } 
}*/ 
enterDays.onclick = calculateDays; 

當我輸入此代碼時,window.prompt正常工作。但是當我取消註釋function.calculateDays時,window.prompt停止工作。任何人都可以解釋爲什麼會發生,以及如何解決它? 非常感謝!window.prompt添加功能時停止工作

+4

這是因爲'function.calculateDays'是一個語法錯誤。它是'功能calculateDays' – baao

+0

什麼是投票關閉作爲一個服務器故障問題? – Teemu

回答

0

function.calculateDays是無效的語法,並會拋出一個語法錯誤,將阻止未來的代碼調用,修復它用function calculateDays替換它。

+0

非常感謝! – NewbieCoder