scrimba
Frontend Career Path
Working with APIs
Async JS
War - Display our card images
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

War - Display our card images
AboutCommentsNotes
War - Display our card images
Expand for more info
index.js
run
preview
console
let deckId

function handleClick() {
fetch("https://apis.scrimba.com/deckofcards/api/deck/new/shuffle/")
.then(res => res.json())
.then(data => {
console.log(data)
deckId = data.deck_id
})
}

document.getElementById("new-deck").addEventListener("click", handleClick)

document.getElementById("draw-cards").addEventListener("click", () => {
fetch(`https://apis.scrimba.com/deckofcards/api/deck/${deckId}/draw/?count=2`)
.then(res => res.json())
.then(data => console.log(data))
})
/**
* Challenge:
*
* Display the images of the 2 cards you drew in the browser.
* Probably best to use `innerHTML` to insert a couple <img> elements
* on the page.
*/
Console
{success:
true
, deck_id:
"dhpkowhwy4xf"
, remaining:
52
, shuffled:
true
}
,
{success:
true
, deck_id:
"dhpkowhwy4xf"
, cards:
[
{code:
"2S"
, image:
"https://deckofcardsapi.com/static/img/2S.png"
, images:
{svg:
"https://deckofcardsapi.com/static/img/2S.svg"
, png:
"https://deckofcardsapi.com/static/img/2S.png"
}
, value:
"2"
, suit:
"SPADES"
}
,
{code:
"8H"
, image:
"https://deckofcardsapi.com/static/img/8H.png"
, images:
{svg:
"https://deckofcardsapi.com/static/img/8H.svg"
, png:
"https://deckofcardsapi.com/static/img/8H.png"
}
, value:
"8"
, suit:
"HEARTS"
}
]
, remaining:
50
}
,
/index.html
-3:59