Ask Question
19 May, 04:11

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

+3
Answers (1)
  1. 19 May, 06:18
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers