player.playVideo is not a function

I hope someone can help with this.

I am getting the following error:

Uncaught TypeError: player.playVideo is not a function

To Reproduce: Click Run, then the play image, do it repeatedly until the error message comes up.

How would that be fixed in the code?

So that error message doesn’t come up.

Click Run, not update to text code: https://jsitor.com/fH5DO8ZU6L

const manageCover = (function makeManageCover() {
    const config = {};

    function show(el) {
        el.classList.remove("hide");
    }

    function hide(el) {
        el.classList.add("hide");
    }

    function hideAll(elements) {
        elements.forEach(hide);
    }

    function showCovers(playButton) {
        const cover = playButton.parentElement;
        cover.classList.add("active");
        show(cover);
    }

    function coverClickHandler(evt) {
        hideAll(config.containers);
        const cover = evt.currentTarget;
        showCovers(cover);
    }

    function addClickToButtons(playButtons) {
        playButtons.forEach(function addEventHandler(playButton) {
            playButton.addEventListener("click", coverClickHandler);
        });
    }

    function init(selectors) {
        config.containers = document.querySelectorAll(selectors.container);
        const playButtons = document.querySelectorAll(selectors.playButton);
        addClickToButtons(playButtons);
    }

    return {
        init
    };
}());
manageCover.init({
    container: ".container",
    playButton: ".thePlay"
});

const videoPlayer = (function makeVideoPlayer() {
    "use strict";

    let player = null;

    const tag = document.createElement("script");
    tag.src = "https://www.youtube.com/iframe_api";
    const firstScriptTag = document.getElementsByTagName("script")[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    function shufflePlaylist(player) {
        player.setShuffle(true);
        player.playVideoAt(0);
        player.stopVideo();
    }

    function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100);
        shufflePlaylist(player);
    }

    function addPlayer(video) {

        const playlist = "0dgNc5S8cLI,mnfmQe8Mv1g";

        const config = {
            height: 360,
            host: "https://www.youtube-nocookie.com",
            width: 640
        };
        config.playerVars = {
            autoplay: 0,
            cc_load_policy: 0,
            controls: 1,
            disablekb: 1,
            fs: 0,
            iv_load_policy: 3,
            loop: 1,
            playlist,
            rel: 0
        };
        config.events = {
            "onReady": onPlayerReady
        };
        player = new YT.Player(video, config);

    }

    function play() {
        player.playVideo();
    }
    return {
        addPlayer,
        play
    };
}());

function onYouTubeIframeAPIReady() {
    const cover = document.querySelector(".playa");
    const wrapper = cover.parentElement;
    const frameContainer = wrapper.querySelector(".video");
    videoPlayer.addPlayer(frameContainer);
}

(function iife() {
    "use strict";

    function coverClickHandler() {
        videoPlayer.play();
    }

    const cover = document.querySelector(".playa");
    cover.addEventListener("click", coverClickHandler);
}());

enter image description here

Answer

I could solve it by wrapping line 99 with a if(player.playVideo)

function play() {
  if (player.playVideo)
    player.playVideo();
}