STUCK here..........................(:

Tell us what’s happening:
Describe your issue in detail here.

I’m stuck I couldn’t understand this task… Could someone help me, please?

cheers.

  **Your code so far**

class Thermostat {
constructor(tem){
  this._tem = tem;
} 

//get 
get c() {
  return.this. = 5/9 * (F - 32);
}
//setter 
set f() {
  return this.c
}

}

const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Use getters and setters to Control Access to an Object

Link to the challenge:

First steps in objective approach is such a fun time, when you look back on it.

Typo on this line. Fix it.

Then read this friendly tutorial, or go watch a movie.

Oh, and give yoursef some time. If you will learn OOP within a week that is reasonable.

hmm … Thanks MyTrueName :lying_face:

I would be glad to help you more, but explaining OOP well is a lot of work, and that was done many times by others. They did it better than me, too.

Best I can do is point you in that direction.

Let’s step back here.

Did you fix the typo @thepannu786? Does your code work now? Do you need more help?

I think there is more going on, but we’ll need to see your updated code to help more.

For instance, you need to make a getter and setter for temperature, not c and f. Your setter should have an argument, the value the user would like to set the temperature to be.

Hi JeremyLT thanks for checking up on me …

unfortunately, that didn’t work. I didn’t want to be mean, ASSHOLE or make her feel like her solution didn’t work for me so I didn’t mention it :worried:

so far this is what I did but no luck
class Thermostat {

constructor(fahrenheit){

    this.fahrenheit = fahrenheit;

  }

  get celsius() {

    return 5/9 * (this._fahrenheit - 32);

  }

  set celsius(tempe) {

    return this._fahrenheit = this._clesius * 9.0 / 5 + 32

  }

}

const thermos = new Thermostat(76); // Setting in Fahrenheit scale

let temp = thermos.temperature; // 24.44 in Celsius

thermos.temperature = 26;

temp = thermos.temperature; // 26 in Celsius

I’ve edited your post for readability. 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 (’).

I appreciate it MyTrueName :slightly_smiling_face:

Thanks heaps

Getting closer!

This getter and your setter need to be for temperature instead of celsius

This formula should use the argument to the setter fun, tempe

Oh I’ll make sure for next time thanks for mentioning it.

Hmm thanks for the help I will work on this tomorrow as it is now 0037 here and my brain could use some rest. I’m not gonna skip this until I understand it very well. If I get stuck again I might call for help.

I did not take offence or felt bad about your answer, don’t worry. I’ve got a thick skin. ; )

There are many things that were wrong with your code, so there was no point solving every single mistake little by little.

It shows that you were not grasping OOP concepts, so the best thing to do time-wise is try to learn it from the very basics. That’s why my answer was just a pointer to tutorials.

What I mean is - you can try to debug your app for 3 hours or you can watch tutorial in 2 hours and try to debug your app in the last hour. That is a better approach time-wise.

Hope you will get it fast. : )

Yea… … Appreciate it

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