Search code examples
javascriptnode.jsclassobjecttwilio

"Twilio Quest" challenge, any help would be appreciated, I dont know what I'm doing wrong,


Can't seem to get a hang of this "Twilio Quest" Challenge.

Hey, I've been playing this game called "Twilio Quest" for the past week.
I just wanted to learn JavaScript, and I think it looked kinda neat.
The challenges served has been up and down in difficulty. But I've always managed to get around, until now.
Been reading through: JavaScript.info - Classes, MDN - Classes, JavaScript.info - Object literal notation and MDN - Object Initialization I tried alot of aproaches. But I really can't seem to get a hang of this challenge.

Heres what I'm trying to do:

class TargetingSolution {
  constructor(config) {
    // your code here
  }

  // your code here
}

// The following lines of code are not required for the solution, but can be
// used by you to test your solution.
const m = new TargetingSolution({
  x: 10,
  y: 15,
  z: 900
});

console.log(m.target()); // would print "(10, 15, 900)"

Solution

  • class TargetingSolution {
      constructor(config) {
        this.value = `(${config.x}, ${config.y}, ${config.z})`
        this.target = () => this.value;
      }
    }
    
    let m = new TargetingSolution({
      x: 10,
      y: 15,
      z: 900
    });
    
    console.log(m.target());