There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Also, heads up for anyone running into the same issue: sometimes an error persists even after correcting it - meaning the console still throws an error message. You need to reload the whole page in that case.
namespace ReturnErrors
{
class Program
{
static void Main(string args)
{
Console.WriteLine(DecoratePlanet(“Mars”));
Console.WriteLine(“Is Pluto really a dwarf…?”);
Console.WriteLine(IsPlutoADwarf(true));
Console.WriteLine(“Then how many planets are there in the galaxy…?”);
Console.WriteLine(CountThePlanets());
}
Please fix this error CC. I love this website for making my life simpler in learning new code! Error Below (starts after step 3 and will not properly compile step 4 without this error persisting):
The build failed. Fix the build errors and run again. "
My code:
" using System;
namespace ReturnErrors
{
class Program
{
static void Main(string args)
{
Console.WriteLine(DecoratePlanet(“Mars”));
Console.WriteLine(“Is Pluto really a dwarf…?”);
Console.WriteLine(IsPlutoADwarf());
Console.WriteLine(“Then how many planets are there in the galaxy…?”);
Console.WriteLine(CountThePlanets());
}
{
class Program
{
static void Main(string args)
{
Console.WriteLine(DecoratePlanet(“Mars”));
Console.WriteLine(“Is Pluto really a dwarf…?”);
Console.WriteLine(IsPlutoADwarf());
Console.WriteLine(“Then how many planets are there in the galaxy…?”);
Console.WriteLine(CountThePlanets());
}
defines a bolean variable and sets it to true, the same is
bool answer; // variable definition
answer = true; // set a value to the variable
Good practice recommends that variables definitions to be the first on our methods or programs
We shouldn’t create variables at the middle or at the end of the programs. We can’t use them before declaring it.
Then you can return a boolean value with
return answer;
or
return true;
Watch the steps:
1. Define a variable;
2. Set it a value;
3. Return it's value;
With
return bool answer=true;
you are defining a variable, setting it a value and returning it’s value in just one line; that’s doesn’t exist in C# language (or any other programing language…)
It seems like you can use strings or values without declaring the variable first. Why Is that?
namespace ReturnErrors
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DecoratePlanet("Mars"));
Console.WriteLine("Is Pluto really a dwarf...?");
Console.WriteLine(IsPlutoADwarf());
Console.WriteLine("Then how many planets are there in the galaxy...?");
Console.WriteLine(CountThePlanets());
}
static string DecoratePlanet(string planet)
{
return $"*..*..* Welcome to {planet} *..*..*";
}
static bool IsPlutoADwarf()
{
bool answer = true;
return answer;
}
static string CountThePlanets()
{
return "8 planets, usually";
}
}
}
I figured for DecoratePlanet to contain some sort of Console.readLine with a defined variable and string data type as it needs input from another method to finish out the string it’s own method used. This goes for CountThePlanets as well. It returns a value without ever declaring a variable or data type within the method. Is this pretty much declared within the input and output parameters and the system just recognizes it?