第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何檢查 if 條件用戶輸入的單詞是否存在于分配給變量的數(shù)組中

如何檢查 if 條件用戶輸入的單詞是否存在于分配給變量的數(shù)組中

夢(mèng)里花落0921 2023-11-11 16:06:56
請(qǐng)參閱評(píng)論后的第2行。這個(gè)問(wèn)題在代碼注釋中有提到。//valid input to be taken by uservar validanswerone = ["yes" , "YES", "Yes"];//here i want to take multiple form of input the user might type but my efforts are going effort less.var validanswertwo = "no";//only this is working.//conditionsif (userage === validanswerone){  console.log("\n\nPlease put your credit card details in the next page" + ", you will be redirected soon!");}else if(userage === 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!")}
查看完整描述

4 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

validanswerone是一個(gè)數(shù)組,您應(yīng)該使用以下命令檢查它Array#includes

if?(validanswerone.includes(userage))?{
???...
}


查看完整回答
反對(duì) 回復(fù) 2023-11-11
?
素胚勾勒不出你

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)題!


查看完整回答
反對(duì) 回復(fù) 2023-11-11
?
ibeautiful

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)用比較邏輯。



查看完整回答
反對(duì) 回復(fù) 2023-11-11
?
慕妹3242003

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ù)檢查它)



查看完整回答
反對(duì) 回復(fù) 2023-11-11
  • 4 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)