[Some bug] Use getters and setters to Control Access to an Object

[Some bug] Use getters and setters to Control Access to an Object
0.0 0

#1

Tell us what’s happening:
I only used the class keyword without the constructor method. I don’t think it should accepted as passed. For some reason this code passes.

Maybe some introduced a bug in to it.

Your code so far


function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Thermostat {
    
  }
  /* Alter code above this line */
  return Thermostat;
}
const Thermostat = makeClass();
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object


#2

Good catch!

I just checked the tests for this challenge. It seems they just check if there is a class defined as source level, and other tests are based on output.

I’m not JS expert, but seems JS/ES is not strict enough, and you can just have a field of an object at runtime created.

If you put console.log(thermos.temperature); after line thermos.temperature = 26;, you confirm.

I’m going to report this bug on FCC github page(or you can do it too dear), and hope soon they could push an update with better testing.

Thanks again for reporting it, Keep going on great work, happy programming.


[Some bug ] Use class Syntax to Define a Constructor Function
#3

Thank you again comrade, good catch. Really appreciated it.


#4

Same thing is happening to this exercise too.

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function


#5

Thank you so much for reporting possible issues you may please create a new post, and specify the faulty code could pass the test? just like this one you did it very good.

Thank you so much.


#6

Ok, just made the post.