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!
Agree with a comment or answer? Like () to up-vote the contribution!
I just wanted to say that I made my own version of the lesson on codeacademy, thought I may as well show people what I did…
This is the entire code:
using System;
namespace PlanetCalculations
{
class Program
{
static void Main(string args)
{
Console.WriteLine(“Type your age into the code.”);
// Your Age
int userAge = 13;
// Length of years on Jupiter (in Earth years)
double jupiterYears = 11.86;
// Age on Jupiter
double jupiterAge = userAge/jupiterYears;
// Time to Jupiter
double journeyToJupiter = 6.142466;
// New Age on Earth
double newEarthAge = userAge + journeyToJupiter;
// New Age on Jupiter
double newJupiterAge = newEarthAge/jupiterYears;
// Log calculations to console
Console.WriteLine("If you are {userAge},");
Console.WriteLine(“Then you are {jupiterAge} year/years old on Jupiter.”);
Console.WriteLine(“Since it takes 6.142466 years to travel to Jupiter,”);
Console.WriteLine("Then you would be {newEarthAge} by the time you reach Jupiter in Earth years.");
Console.WriteLine(“In Jupiter years, you would be {newJupiterAge} years old by the time you reached Jupiter.”);
Console.WriteLine(“Cool Right?!”);
}
}
}
Hey @fluffymuffinsareawes, the reason that the errors occur is… You need to use string interpolation, I don’t know much about this yet, but I know that string interpolation can be acheived by using the $ mark before a string.
An example:
What am I doing wrong??? I’m new to this FYI
// Log calculations to console
Console.Writeline(userAge);
Console.Writeline(newEarthAge);
Console.Writeline(userAge+journeyToJupiter);
Console.Writeline(double newJupiterAge=newEarthAge/jupiterYears);
I was wondering the same thing. It made sense when I changed ‘%20’ to ‘+’. Do Americans write ‘percent twenty’ when they want to say ‘plus’? I don’t think so.
You already made the calculation (variable) for each age.
in //Log calculation to console, you were asked to print the result to the console.
Not to calculate again. So the code will turn like this.
I think its because its adding ur age u are as ur leaving earth to the age u are when ur on Jupiter if any of you are wondering it was very simple actually.
“Console.WriteLine” puts the answer on a new line by itself. This is good to use if you have many different integers that you want on separate lines rather than running them all together on one line.
“Console.Write” prints the output on a single line. If you have four different integers and you print them all using Console.Write, they will all run together on a single line.
in the end part (No.6 - logging your answers) seeing as your variable answers are in {} brackets you need to utilise string interpolation. You could just concatinate them like "some text " + yourVariable
The issue with this section is the system seems to only allow the below as as acceptable answer before allowing you to go to Next section (which is silly to me… seems like misinformation in the question). you need to add below code it will work.
In task number five, I tried solving it using the code:
"
// New Age on Jupiter
double newJupiterAge = jupiterAge + (journeyToJupiter / jupiterYears);
"
This gives an error. As the editor wants you to do
"
// New Age on Jupiter
double newJupiterAge = newEarthAge / jupiterYears;
"
even though the values are the same. My logic was, even though the code was longer, it would work regardless of whether or not newEarthAge was known and defined. I chose to base it on the base defined values to save time when having to reformat the code, if you did not want to store newEarthAge anymore, you would have to rewrite newJupiterAge as well. Shouldn’t my solution be valid as well and the other given as an alternative solution to the problem?
Thought about this problem: Why don’t we cast the newAge types back into integers? This lesson is directly after the casting lesson and I feel these values are appropriately represented as an int.