C# C# Basics If Statements "else if" and "else" Statements

Ilya Sikharulidze
PRO
Ilya Sikharulidze
Pro Student 1,071 Points

Can someone please help me, I don't understand how to use 'return' value in this case

Program.cs
using System;

class Program
{

    static string CheckSpeed(double speed)
    {

        if(speed > 65.0)
        {
             Console.WriteLine("too fast");
        }
        else if(speed < 45.0)
        {
            Console.WriteLine("too slow");
        }
        else
        {
            Console.WriteLine("speed OK");
        }// YOUR CODE HERE

    }

    static void Main(string[] args)
    {
        // This should print "too slow".
        Console.WriteLine(CheckSpeed(44));
        // This should print "too fast".
        Console.WriteLine(CheckSpeed(88));
        // This should print "speed OK".
        Console.WriteLine(CheckSpeed(55));
    }

}

2 Answers

Steven Parker
Steven Parker
177,602 Points

Ilya Sikharulidze — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

Steven Parker
Steven Parker
177,602 Points

You're pretty close there. But instead of outputting the strings directly (using "Console.WriteLine"), your code should return the string values (using "return").

Ilya Sikharulidze
Ilya Sikharulidze
Pro Student 1,071 Points

Thanks, I understand that, but I don't understand how to exactly to implement the "return"

Steven Parker
Steven Parker
177,602 Points

Where you currently have the term "Console.WriteLine" (in 3 places), replace it with the word "return". Optionally, you can also remove the parentheses around the string (replacing the open parenthesis with a space).