Create a function formatWeatherReport which takes 3 parameters : cityName, tempC and showFahrenheit

who can help me solve this code pls. Create a function formatWeatherReport which takes 3 parameters : cityName, tempC and showFahrenheit and returns the weather report string like this: ```
In Vancouver it is currently :cold_face: 37.4°F
In New Delhi it is currently :hot_face: 35°C
In Sydney it is currently :blush: 17°C
In Miami it is currently :hot_face: 104°F

console.log(result);// "In Vancouver it is currently 🥶 42.8°F"

hi there,

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

1 Like

Thank you, will put in effort atleast 4-5 hours per day on FCC curriculum


Here is what i have been working on but i feel stuck somewhere. it says i should use the previous functions i created which was formatTemperatureAsString and convertToEmojiFace to write a function formatWeatherReport

can you share the code in a pastebin or copy the actual code here? (pictures of code are hard to read)

function convertToFahrenheit(tempc){
  return tempc * 9/5 + 32;
}

function formatTemperatureAsString(tempc, convertToF){
    if (convertToF === true){
        return convertToFahrenheit(tempc) + "°F";
    }
    else {
        return tempc + "°C";
    }
}
function convertToEmojiFace(tempc){
    if (tempc > 30){
        return "🥵";
    }
    else if (tempc > 12){
        return "😊";
    }
    else {
        return "🥶";
    }
}
function formatWeatherReport(cityName, tempc, showFahrenheit){
    if (showFahrenheit === false){
        return convertToEmojiFace + formatTemperatureAsString;
    }
    else if(tempc > 6){
        return tempc;
    }
    else{
        return "In" + cityName + "it is currently" + tempc * 9/5 + 32;  
    }
}
let result = formatWeatherReport('Vancouver', 6, true);
console.log(result);// "In Vancouver it is currently 🥶 42.8°F"

look at your code again. Do you see the redundancy?
You have in multiple places the formula for calculating Fahrenheit.

also it looks like you are not calling the functions properly (you need to pass some arguments to the functions as needed)

Edit: also why are you treating temp > 6 in a special way?
For all temps you should have been using the same code.

When you concatenate a string with a number, the result is a string. JavaScript first concatenates the string “InVancouverit is currently” with temppc * 9/5 to get the following string:

InVancouverit is currently10.8

Next the +32 concatenates 32 to the end of the first string, resulting in:

InVancouverit is currently 10.832

If you wrap the the part of the return value that is to be calculated with ( and ), the resulting number 42.8 would be concatenated to the end of the string InVancouverit is currently

okay thanks for the tips, let work it out again

1 Like

thanks for the response, i was thinking since tempc is 6, i will result to 10.832 + 32 which should print 42.832

You made a call with the second argument as the number 6. Since, 6 is not greater than 6, the else code block runs as I described above.

This is how the code should be. i’m supposed to get weatherreport using the previous two functions but i am lost. been trying to code this for more than an hour

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

okay thank you, taken note of that

Just try to look at what you have already.

1- you have a function convertToFahrenheit which takes a temp in C and returns the Fahrenheit value, correct? So whenever you need to change C to F, use it.

2- you have a function formatTemperatureAsString which takes a temp in C and 2nd param to decide if it should be shown in C or F and then it produces something formatted for printing made up of the temp and the units. So use this whenever you need to print the temp with its units

3- you have a function convertToEmojiFace which take a temp in C and produces an emoji. So use that when you need an emoji

Combine these three to produce the formatted result you’ve been asked to provide.

You can achieve what you want with one or two lines of code in the formatWeatherReport function. Make sure you add space characters as appropriate to get the desired output.

i will really put in time on the FCC curriculum atleast 4 hours a day to see how things goes for me . i desperately want to master javascript