<html>
<head>
<title></title>
<script src="https:/code.jquery.com/jquery-3.2.1.js"></script>
</head>
<body>
<button>Button</button>
<script>
var user_response='';
$('button').on('click',ask_a_question);
function ask_a_question(){
user_response = prompt('What is your item name?').toLowerCase();
if (user_response === 'apple')
//Between here is where i dont understand why,
//when the if statement is true, that it does not "alert" the bucketlist
//variable and then tells the user **"'learn to juggle', 'take a falconry
//class', 'climb mt everest'."** Does this code even make sense?
alert(bucketList);
var bucketList = [
'learn to juggle',
'take a falconry class',
'climb Mt Everest'
];
}
</script>
</body>
</html>
1
A
回答
4
您正試圖在定義它們之前顯示bucketList的值。
嘗試移動
var bucketList = [
'learn to juggle',
'take a falconry class',
'climb Mt Everest'
];
上述alert(bucketList);
+1
非常感謝你 –
1
,我得到了警告,指出「未定義」。
如果我將警報移至定義bucketlist的位置之後,我會看到顯示陣列內容的警報。
相關問題
- 1. 如何停止代碼運行,如果不滿足語句
- 2. 我可以在哪裏編寫不斷運行的代碼?
- 3. 我可以在每條語句的多行上編寫PHP代碼嗎?
- 4. 爲什麼Maven會提醒我編碼?
- 5. 如果語句代碼
- 6. 如何運行QT2編寫的代碼?
- 7. 當我的代碼不僅會提醒一次?
- 8. 爲什麼我不能在通常的語句中編寫這段代碼?
- 9. Android_Eclipse代碼不承認,如果語句
- 10. 爲什麼代碼不提醒Worky-worky?
- 11. 如果try語句在python中成功運行代碼
- 12. 如果語句運行不正常
- 13. 的意外行爲如果在PHP代碼語句
- 14. 爲什麼我的C#if語句代碼不工作?
- 15. 爲什麼我的代碼不執行break語句?
- 16. 量角器 - 我想寫如果ELSE語句DRYer,如果可能
- 17. 爲可變數量記錄的INSERT INTO xxx()VALUES(),(),(),...編寫語句?
- 18. 運行在Scala代碼多hiveQL語句
- 19. 代碼重複運行其他語句
- 20. 如何用不可變集合和適當的語句寫適當的Scala?
- 21. 如果變量已存在,則不運行if語句
- 22. jquery不會改變寬度但是如果語句運行
- 23. nextLine(),當我運行我的代碼
- 24. 爲什麼我的代碼運行速度更快,如果我編譯codeBlocks
- 25. PHP mysqli編寫語句不起作用
- 26. 如何將此語句寫入編碼?
- 27. 如果瀏覽器不支持代碼,則顯示提醒
- 28. 如果語句條件不符合,代碼仍在執行
- 29. 如果我的IF語句爲假,我如何獲得我的if/else語句來運行一堆函數?
- 30. C++如果語句行爲不正確
嘗試它的定義之前,提醒的東西是徒勞 – adeneo
把'alert'後'bucketList'。警報本質上是阻塞的。所以'bucketList'只有在你接受alert的時候才被定義,這就是爲什麼你得到undefined – Ionut
雖然javascript中的var被掛起,但是賦值並不是。就像所有人都說的,在定義陣列之前提醒您。 – Keith