我的目标:
我正在尝试在我的网站上创建一小部分用于推荐。
我有 1 个推荐,当点击按钮时,当前的推荐消失,一个新的随机推荐出现在框中。这工作正常。但是...我注意到随机选择器抛出了重复的推荐(显示了推荐 1,单击了按钮并且仍然偶然出现了推荐 1)
我正在尝试编写一个命令,上面写着:如果新数组与前一个数组相同,则重复随机选择过程(重做数学),否则写入(innerHTML)新的推荐。
我的问题是我不知道 IF 部分的编码(我在其中潦草地写着“与当前消息相同”)
下一阶段将是“开始脚本”部分(重做数学)
如果有人可以在这里帮助我,我将不胜感激,因为我有点笨拙!
先感谢您
function quotes() {
//Define and populate the array
var aquote = new Array;
aquote[0] = "\"Your cakes are fantastic, beautiful designs and taste gorgeous!\"";
aquote[1] = "\"I can’t believe how beautiful the cake was and how much detail there was on it. My mum cried when she saw it and didn’t want to cut it up but we eventually persuaded her and it was really tasty.\" Sasha – Rothwell";
aquote[2] = "\"Thank you for our wedding cake. The fruit cake was absolutely delicious and so moist. The flowers you made were beautiful and exactly as we imagined they would be. We have kept the flowers and they are a great reminder of our wonderful day.\" Paul & Jane – Rutland"
aquote[3] = "\"My husband said that the cupcakes you made for his birthday are the best he has tasted and your buttercream is divine – I have to agree!\" Dawn – Cambridgeshire"
aquote[4] = "\"Thank you Bumble Cottage Cakes for My son’s birthday cake it was fantastic as usual I will be back soon and I can’t wait for the next one.\"Liz – Desborough"
//Generate a random number then print the quote from that array index
rdmQuote = Math.floor(Math.random() * aquote.length);
if (rdmQuote = aquote[SAME AS CURRENT MESSAGE]) {
alert('quote is same as current')
} else {
document.getElementById("randomtestimonial").innerHTML = aquote[rdmQuote];
}
}