BETA: ES6: Use class Syntax to Define a Constructor Function (Template Code issue)
See original GitHub issueChallenge 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:
- Created 5 years ago
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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,
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.