简体   繁体   中英

How do I store multiple values at one array index?

I've tried to do

'somethin' || 'something'

in an array, but when I did

let answers = ['object oriented programming' || 'oop', '2 + 2' || '2+2', 'bark', 'the stone table' || 'stone table', 'a bridge' || 'bridge', 'the riddle of the day!' || 'the riddle of the day' || 'riddle of the day!' || 'riddle of the day', 'food']

if (prompt(riddles[0]).toLowerCase() == answers[0]) {
    console.log('Yes!!!')
} else {
    console.log('Sorry, but no. :|')
}

the console said, "Sorry, but no. :|."

Am I supposed to do something with the || (the 'or' statement)?

Use a nested array to store multiple values:

let answers = [['object oriented programming', 'oop'], ['2 + 2', '2+2'], ['bark'], ['the stone table', 'stone table'], ['a bridge', 'bridge'], ['the riddle of the day!', 'the riddle of the day', 'riddle of the day!', 'riddle of the day'], ['food']];

if (answers[0].includes(prompt(riddles[0]).toLowerCase())) {
    console.log('Yes!!!')
} else {
    console.log('Sorry, but no. :|')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM