需要一点帮助。 我需要从yesOrNo .toLowerCase()和.charAt(0)做出响应,同时检查响应是==到'y'。 任何帮助表示感谢。
<!doctype html>
<title>'Schittys Pizza'</title>
<script>
// Asks if you want to order
var yesOrNo = prompt('Welcome to Schitty\'s pizza, would you like to order?, Yes or No?');
if(yesOrNo == 'y') {
// Asks Address
var address = prompt('What is your Address?')
while (address == null || address == '')
address = prompt('What is your address, please?')
}
</script>
答案 0 :(得分:0)
试试这个
var yesOrNo = prompt('Welcome to Schitty\'s pizza, would you like to order?, Yes or No?').toLowerCase()[0];
if(yesOrNo === 'y') {
// do your yes logic
}
或
var yesOrNo = prompt('Welcome to Schitty\'s pizza, would you like to order?, Yes or No?').toLowerCase();
if(yesOrNo[0] === 'y') {
// do your yes logic
}
或
var yesOrNo = prompt('Welcome to Schitty\'s pizza, would you like to order?, Yes or No?');
if(yesOrNo.toLowerCase()[0] === 'y') {
// do your yes logic
}
或
var yesOrNo = prompt('Welcome to Schitty\'s pizza, would you like to order?, Yes or No?');
if(yesOrNo.toLowerCase().charAt(0) === 'y') {
// do your yes logic
}