question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BETA: ES6: Use class Syntax to Define a Constructor Function (Template Code issue)

See original GitHub issue

Challenge Name

https://beta.freecodecamp.org/en/challenges/es6/use-class-syntax-to-define-a-constructor-function

Issue Description

The default code to be changed incorrectly says “change between these lines,” when more extensive editing needs to be done. Current state:

function makeClass() {
  "use strict";
  /* Alter code below this line */

  /* Alter code above this line */
  return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

My solution to this challenge (bottom of page) shows the issue.

Suggested replacement:

 /* Alter code below this line */
function makeClass() {
  "use strict";

  return Vegetable;
}
/* Alter code above this line */
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

Browser Information

  • Browser Name, Version: Firefox 59.0.1
  • Operating System: Win 8.1
  • Mobile, Desktop, or Tablet: Desktop

Your Code

class Vegetable {
  constructor(name){
    this.name = name;
  }
}

const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot

Screenshot

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rajatkantinandicommented, May 25, 2018

The current seed is absolutely fine, because it asks the user to create a class inside the makeClass() function & return it & passes the challenge with the following code:

function makeClass() {
  "use strict";
  /* Alter code below this line */
    class Vegetable{
      constructor(name){
        this.name=name;
      }
    }
  /* Alter code above this line */
  return Vegetable;
}
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

This way of returning a class from a function refers to the fact that a class is nothing but a kind of JS function internally which can be returned from another function & assigned to other variables just like any other JS function or object.

So, I think this is not an issue & should be closed. Although @dearhakeemdavis 's solution seems logical as it will clear all the confusions regarding this challenge. So, either one can add few more comments as suggested by @dearhakeemdavis or leave it as it be. Current “Change between these lines” are perfect otherwise,

0reactions
QuincyLarsoncommented, Jun 3, 2018

I’m closing this issue as stale since it hasn’t been active lately. If you think this is still relevant to the newly updated platform, please explain why, then reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 - Use class Syntax to Define a Constructor Function
In this JavaScript ES6 tutorial we use class syntax to define a constructor function. This is one part of a multi-part series where...
Read more >
Use class Syntax to Define a Constructor Function ... - YouTube
Certification: JavaScript Algorithms and Data Structures Course: ES6 Lesson: Use class Syntax to Define a Constructor Function ...
Read more >
How to Use class Syntax to Define a Constructor Function (ES6
Learn how to define constructor functions by using class syntax. We're almost at 100 subs! If this video helped you out, please remember...
Read more >
Tutorial: Intro to React
In this tutorial, we're using arrow functions, classes, let , and const statements. You can use the Babel REPL to check what ES6...
Read more >
Why You Should Not Use Classes in JavaScript
Objects defined with classes have to explictly use the 'this' keyword. If you pass your class method to a callback, you can run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found