My aim:
I am trying to create a small section on my website for testimonials.
I have 1 testimonial, when the button is clicked, the current testimonial disappears and a new random testimonial appears in the box. This works fine. But... I notice that the random selector is throwing up duplicate testimonials (Testimonial 1 is shown, the button is clicked and testimonial 1 still appears by chance)
I am trying to write a command that says: IF the new array is the same as the previous then repeat the random selection process (redo math) ELSE write (innerHTML) the new testimonial.
My problem is that I don't know the coding for the IF section (where I have scrawled "SAME AS CURRENT MESSAGE")
Also the next stage will be the "go to start of script" part (redo math)
I would really appreciate it if someone could help me out here as I am a bit clueless TBH!
Thank you in advance
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];
}
}