查看创建可重用方法的解决方案

已完成

以下代码是上一单元中所述挑战的一种可能的解决方案。

Random random = new Random();
int luck = random.Next(100);

string[] text = {"You have much to", "Today is a day to", "Whatever work you do", "This is an ideal time to"};
string[] good = {"look forward to.", "try new things!", "is likely to succeed.", "accomplish your dreams!"};
string[] bad = {"fear.", "avoid major decisions.", "may have unexpected outcomes.", "re-evaluate your life."};
string[] neutral = {"appreciate.", "enjoy time with friends.", "should align with your values.", "get in tune with nature."};

TellFortune();
luck = random.Next(100);
TellFortune();

void TellFortune() 
{
    Console.WriteLine("A fortune teller whispers the following words:");
    string[] fortune = (luck > 75 ? good : (luck < 25 ? bad : neutral));
    for (int i = 0; i < 4; i++) 
    {
        Console.Write($"{text[i]} {fortune[i]} ");
    }
}

此代码仅仅是“一种可能的解决方案”,因为你可能已在不同的点添加了换行符,或者你的代码格式可能不同

无论代码存在什么样的细微差异,在运行代码时,都应看到以下两条输出消息:

```Output A
A fortune teller whispers the following words:
You have much to look forward to. Today is a day to try new things! Whatever work you do is likely to succeed. This is an ideal time to accomplish your dreams! 
```

```Output B
A fortune teller whispers the following words:
You have much to appreciate. Today is a day to enjoy time with friends. Whatever work you do should align with your values. This is an ideal time to get in tune with nature. 
```

```Output C
A fortune teller whispers the following words:
You have much to fear. Today is a day to avoid major decisions. Whatever work you do may have unexpected outcomes. This is an ideal time to re-evaluate your life.
```

如果你完成了挑战,恭喜! 继续进行下一个单元中的知识检查。

重要

如果在完成此项挑战时遇到问题,则请先回顾前面的几个单元,然后再继续。 我们在其他模块中讨论的所有新内容都将取决于你对此模块中所介绍内容的理解情况。