Ask Question

Create an array of 10 fortune cookie sayings that will be randomly displayed each time the user reloads the page. The fortune will be sayings like: "Procrastination is the thief of time." Let the visitor get a new fortune when a button is clicked. g

+4
Answers (1)
  1. 25 September, 12:39
    0
    let cookieNumber = Math. floor (Math. random () * 10)

    switch (cookieNumber) {

    case 1:

    document. write ('Fortune 1')

    break;

    case 2:

    document. write ('Fortune 2')

    break;

    case 3:

    document. write ('Fortune 3')

    break;

    case 4:

    document. write ('Fortune 4')

    break;

    case 5:

    document. write ('Fortune 5')

    break;

    case 6:

    document. write ('Fortune 6')

    break;

    case 7:

    document. write ('Fortune 7')

    break;

    case 8:

    document. write ('Fortune 8')

    break;

    case 9:

    document. write ('Fortune 9')

    break;

    case 10:

    document. write ('Fortune 10')

    Explanation:

    The cookieNumber is generated using Math. random (), which is rounded to a whole number using Math. floor (). Then, a switch block is used to display a different fortune depending on the value of cookieNumber.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create an array of 10 fortune cookie sayings that will be randomly displayed each time the user reloads the page. The fortune will be ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers