![](/img/trans.png)
[英]How do i store multiple random values in an array with localstorage
[英]How do I store multiple values at one array index?
我试过做
'somethin' || 'something'
在一个数组中,但是当我这样做时
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. :|')
}
控制台说:“对不起,没有。:|。”
我应该对||
做点什么吗? (“或”语句)?
使用嵌套数组存储多个值:
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. :|')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.