Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Getter

Object-Oriented Programmingmedium

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 227: Setters and Getters

Using a `Temperature` class with a `fahrenheit` getter, implement `toF(celsius)` returning the Fahrenheit value.

Sample tests

Input: toF(0)
Output: 32
Input: toF(100)
Output: 212

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Calling the getter like a method throws.
Visualize this concept: Getters and Setters →
Approach & explanation (try first)

A getter computes a derived value accessed as a property.

Loading...
⌘/Ctrl + Enter

Run your code to see results.