4 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊
validanswerone
是一個(gè)數(shù)組,您應(yīng)該使用以下命令檢查它Array#includes
:
if?(validanswerone.includes(userage))?{ ???... }

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
這是問(wèn)題的解決方案。通過(guò)使用將所有輸入轉(zhuǎn)換為大寫(xiě)或小寫(xiě)
var age = userage.toUpperCase();
我能夠以任何格式輸入輸入,該輸入會(huì)自動(dòng)轉(zhuǎn)換為我的條件,在本例中為大寫(xiě)。
請(qǐng)有人幫助我正確地重新表述問(wèn)題并發(fā)布答案,以便需要此答案的人能夠輕松找到它。
var readlineSync = require('readline-sync');
//question asked to the user
var userage = readlineSync.question("Are you above the age of 18 for the purchase of the tickets \n(*as of DEC-2020) " + " : ");
var age = userage.toUpperCase();
//valid input to be taken by user
var validanswerone = "YES";
var validanswertwo = "NO";
//conditions
if (age === validanswerone){
console.log("\n\nPlease put your credit card details in the next page" + ", you will be redirected soon!");
}
else if(age === validanswertwo){
console.log("\n\nWe are sorry!");
console.log("\n\nPlease try back in" + " *days remaining to be become 18+ will be added in the coming update still not understood the formula to implicate it*");
}
else{
console.log("\n\nInvalid input!")
}
//final-output
console.log("\n\nThank you, you will be redirected soon!")
希望有一天這能解決某人的一些問(wèn)題!

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果數(shù)組僅包含字符串值,并且數(shù)組包含類似 [ {id:1,name:"Aditya"} ] 的對(duì)象,則可以使用Array.includes() 。那么您應(yīng)該使用Array.some()因?yàn)樗诘鷶?shù)組中的事件元素時(shí)應(yīng)用比較邏輯。

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用 JavaScript 中的 include 函數(shù),無(wú)論數(shù)組中是否存在用戶,它都可以為您提供輸出!像這樣“validanswerone.includes(userage)”,更好的方法是如果您僅為多種形式的 YES 或 NO 創(chuàng)建一個(gè)數(shù)組(您可以使用 .tolower 或 .toCapital 函數(shù)檢查它)
添加回答
舉報(bào)