jeudi 13 octobre 2022

Math.random create random sentences with 3 different arrays [duplicate]

  1. Make sentences from the three arrays. Firt index with first index form each array so on.. 10 sentences. (This I have figured out and managed)
  2. Use Math.random to mix the words from the arrays randomly to make new sentences, doesnt matter if a word get used two times.

Question: where do i best put the Math.random in my code?

let substantiv = ['Daddy', 'Jag', 'Hästen', 'Mamma', 'Glaset', 'Gameboy', 'Pelle','Blondie', 'Sängen', 'Bilen']
let verb = ['cyklar', 'rider', 'bakar', 'springer', 'hoppar', 'äter', 'dricker', 'går', 'läser', 'sover']
let adj = ['bra', 'dåligt', 'roligt', 'inte', 'alltid', 'på Söndag', 'aldrig', 'imorgon', 'idag', 'snabbt']

let cont = document.createElement('div')
document.body.append(cont)


for(let i=0; i<10; i++){
    const el1 = document.createElement('div')
    el1.textContent = `${substantiv[i]} `+`${verb[i]} `+`${adj[i]}`
    cont.append(el1)    
}



Aucun commentaire:

Enregistrer un commentaire