<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>

最佳答案

您试图在定义它们之前显示bucketList的值。

尝试移动

var bucketList = [
    'learn to juggle',
    'take a falconry class',
    'climb Mt Everest'
];


alert(bucketList);以上

09-15 18:11