** Help Needed ** Convert Celsius to Fahrenheit

Tell us what’s happening:
How do I console.log different values (celsius) to the console to see the difference in outcomes?

function convertToF(celsius) {
  let fahrenheit = celsius * 9 / 5 + 32;
  return fahrenheit;
}

convertToF(30);

What have you tried? What problems have you had?
To log the value of celsius you would use console.log(celsius);

I want to test for different values through the conversion from Celsius to Fahrenheit, and have it shown in the console.

I tried console.log(celsius) but it says “ReferenceError: celsius is not defined”.

Where did you put the log statement?

Right below "convertToF(30);. I tried putting it above too, but the result is the same.

I passed the challenge. I just wanted to see how it logs differently on the console based on the values I input.

If you want to see the result of your function, you console.log(functioncall(stuff)) and you get whatever the function returns in the console.
If you want to log some value WITHIN the function, then you write the console.log() inside, with whatever you want to see - keep in mind return ends the funciton, so you cannot log stuff after it.
Also regarding the error: “celsius” is the argument of the function and by default locally bound to the function-scope - meaning it doesn’t “exist” outside the function and cannot be adressed outside. ArielLeslie meant to console.log(celsius) within the funciton.

1 Like

I tried “console.log(convertToF(celsius))” but I don’t think I did it right.

What’s the right way to go about it if I want to see the converted value (in fahrenheit)?

The variable celsius only exists inside the function convertToF().

2 Likes
function convertToF(celsius) {
  let fahrenheit = celsius * 9 / 5 + 32;
  return fahrenheit;
}

convertToF(30);

When I change the value from 30 C to 40 C, what should I do to see the value post-conversion logged onto the console?

You could just do it like this…

Option1: Log the function call output itself.
console.log(convertToF(30));

Option2: Log inside the function the input and calculated output

function convertToF(celsius) {
  console.log('Input argument in celsius:', celsius);
  let fahrenheit = celsius * 9 / 5 + 32;
 console.log('Output value in Fahrenheit:', fahrenheit);
  return fahrenheit;
}
2 Likes

If you want to log the result of a called function, you can do that.

console.log(convertToF(30));
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.