0
我在問用戶一個問題,我希望他們的答案不區分大小寫。無論他們是否使用大寫字母,他們都應該有正確的答案。任何幫助,這將不勝感激。製作答案不區分大小寫
var name = prompt('Enter your name');
var correctAnswers = 0;
var questions = 15;
document.write('Okay '+name+' here is Question 1: What does html stand for?: HyperText Markup Language, High Track Making Language, High Tech Making Language');
var answer = prompt('Okay '+name+' here is Question 1: What does html stand for?: HyperText Markup Language, High Track Making Language, High Tech Making Language');
if (answer === 'HyperText Markup Language') {
console.log(correctAnswers = correctAnswers + 1);
console.log('That is correct!');
document.write('<div>That is correct!</div>');
} else {
console.log('Sorry that is wrong. The correct answer is HyperText Markup Language.');
document.write('<div>Sorry that is wrong. The correct answer is HyperText Markup Language.</div>');
}
使用'toLowerCase() '將字符串轉換爲小寫,並與全部小寫的答案進行比較。 'answer.toLowerCase()==='超文本標記語言' – Tushar