Ask Question
6 January, 01:04

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

+5
Answers (1)
  1. 6 January, 02:02
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers