-2

I’ve been working on the challenge to get into a bootcamp (as a complete newb) and I hit a bit of a bump

The task is to convert the temperature of 4°C to °F

All versions below work in the developers tool in chrome, however they don’t work on repl.it.

Version 1:

let fahrenheit; //prints nothing on repl.it
let celsius; //works perfect in chrome

function toF(celsius){
   fahrenheit =(celsius*1.8)+32;
   return fahrenheit;
};

console.log(fahrenheit);
toF(4);

Version 2:

let fahrenheit; //prints nothing on repl.it
let celsius; //works perfect in chrome

const converter = celsius =>{
   fahrenheit=(celsius*1.8)+32;
   return fahrenheit;
   console.log(fahrenheit);
};

converter(4);

Version 3:

let fahrenheit; //prints Nothing on repl.it
let celsius; //works perfect in Chrome

function cToF (celsius){
   fahrenheit=(celsius*1.8)+32;
   return fahrenheit;
   console.log(fahrenheit);
};

cToF(4);

any hints as to why are much appreciated

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • So it sounds like repl.it support for ES6 is ... "lacking" (to put it charitably). Q: Do you really *need* repl.it? – paulsm4 Dec 15 '20 at 22:40

3 Answers3

0

You should check supported javascript version at repl.it. Let and arrow functions are ES6, try this (var instead of let):

var fahrenheit; //
var celsius; //

function cToF (celsius){
   fahrenheit=(celsius*1.8)+32;
   console.log(fahrenheit); 
   return fahrenheit;
};

cToF(4);
MRsa
  • 666
  • 4
  • 8
0

Version 1: You are calling the toF() function but at no point in the function do you print to the console. Try this:

console.log(toF(4));

Versions 2 and 3: Your console.log() calls are made after your return statements. Anything after a return statement in your function is unreachable - the return statement exits the function. Here's what Version 2 should look like:

const converter = celsius =>{
   fahrenheit=(celsius*1.8)+32;
   console.log(fahrenheit);
   return fahrenheit;
};

Note the console.log has been moved to before the return statement.

An even better solution would move the console.log outside the function and simply return farenheit here. Then you should call it like this:

console.log(converter(4));
dancingCamel
  • 206
  • 2
  • 8
0

Version 1 prints Fahrenheit before the function is called to change its value. Version 2 unreachable code after return statement: return fahrenheit; console.log(fahrenheit); Version 3 same problem as version 2.

Practice some more, Javascript is the supreme language the best to learn.

Ps:(Go with react if you wanna learn a framework, it is the supreme framework)