I'm currently working on a unique "Show - Actor - Show" button that will display a random show, followed by a cast member from that show, and then another show featuring the same cast member.
While I've managed to generate a random show ID successfully, I am facing challenges in passing that ID into the randomActor function because randomShow isn't a function.
My goal is to have a single button that switches between searching for an actor or show based on the previous search. The main issue lies with my randomActor function as I am struggling to pass the value of the randomShow search into the string template literal.
Any help or advice would be greatly appreciated!
const randomButton = document.querySelector('#randomShow')
const randomShow = randomButton.addEventListener('click', async function (e) {
e.preventDefault();
const randomNumber = Math.floor(Math.random() * 1000);
const res = await axios.get(`http://api.tvmaze.com/shows/${randomNumber}`)
console.log(res.data.id);
return (res.data.id)
})
const randomActor = randomActorButton.addEventListener('click', async function (e) {
e.preventDefault();
const res = await axios.get(`http://api.tvmaze.com/shows/${randomShow.res.data.id}/cast`)
console.log(res.data[0]);
return (res.data[0])
})