vendredi 4 décembre 2020

How do I randomize the outcome of an array, then link it to a conditional

I want to randomize the results from the person array. How do I connect it to the if statement so it randomizes the person each time, and if I load it it gives me a different sentence each time.

let placea = 'Shopping Mall'
let placeb = 'Library'

let person = ['John', 'Sam', 'Ryan', 'Liam', 'David']

if (person === 'John' || person === 'Liam' || person === 'Sam') {
  console.log(`Lets go to the ${placea}`)
} else {
  console.log(`I love quiet places, lets go to the ${placeb}`)
}



Aucun commentaire:

Enregistrer un commentaire