Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Static Method

Object-Oriented Programmingmedium

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 226: ES6 Classes

Define a `MathUtils` class with a static `sumTo(n)` method, and implement `rangeSum(n)` returning `1 + 2 + ... + n` by calling it.

Sample tests

Input: rangeSum(5)
Output: 15
Input: rangeSum(1)
Output: 1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Calling a static method on an instance does not work.

Learning resources

  • MDN: Classes
Visualize this concept: ES6 Classes →
Approach & explanation (try first)

Static methods are utilities on the class itself, invoked without an instance.

Loading...
⌘/Ctrl + Enter

Run your code to see results.