Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Everytime I test my attributes are undefined?

I want to create a class Deck that gets two attributes id and remaining. I use the Deck of Cards API to get the information of a deck but every time I create a Deck I keep getting id and remaining as undefined and I don't understand why because the JSON value is good and when I print it I got something but my attributes are undefined.

 class Deck {

    constructor(numberOfDeck, jokersEnabled) {
        let url;

        if (jokersEnabled) {
            url = "https://www.deckofcardsapi.com/api/deck/new/shuffle/?deck_count=" + numberOfDeck + "&jokers_enabled=true";
        } else {
            url = "https://www.deckofcardsapi.com/api/deck/new/shuffle/?deck_count=" + numberOfDeck;
        }
        console.log(url);
        fetch(url).then(res => res.json()).then(value => {
            this.id = value.deck_id;
            this.remaining = value.remaining;
        }).catch(function(err) {
            console.log(err);
        });
    }
}

let deck = new Deck(1, true);
console.log(deck.id + " " + deck.remaining);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!