2016-02-29 37 views
-1
  1. 請說明parseInt做什麼?
  2. 我不希望任何函數調用來執行代碼。這段代碼爲什麼給我空白頁?

    <html> 
    <head> 
    </head> 
    <body> 
    <script> 
    var a= parseInt(promt("Enter the number")); 
    var b= parseInt(promt("Enter another numbe`enter code here`r")); 
    function addition(param1, param2) 
    { 
    var total =param1+param2; 
    return total; 
    } 
    var result = addition(a,b); 
    document.write(result); 
    </script> 
    </body> 
    </html> 
    
+4

'prompt'拼寫爲'promt'。您的代碼發生錯誤。 –

回答

1

的頁面是因爲在你的代碼中的錯誤的空白。它阻止了document.write的運行。

1)parseInt將字符串更改爲整數(數字)。

2)不確定你是什麼意思的這個問題。如果你僅僅意味着你想要的代碼序列而不在函數內部運行,這將工作:

var a = parseInt(prompt("Enter the number")); 
var b = parseInt(prompt("Enter another number")); 
var total = a+b; 
document.write(total); 

此外,prompt已經拼寫錯誤的promt這是行不通的。這是防止您的代碼成功寫入頁面的錯誤(謝謝Joe Clay)

-1

1)parseInt將字符串更改爲整數。

您犯了一個錯誤:'promt'必須替換爲'prompt'。

相關問題