Playing YouTube videos from an array

defaultOptions variable
const defaultOptions =

Assign
`Object.assign

({},defaults.playerOptions);`

What am I not understanding?

You didn’t say object assign, so maybe you didn’t mean that.

When you say assign, what do you mean by that?

This?
defaultOptions = [defaults.playerOptions]

no, not that.

What is wrong with me, I don’t understand.

I’m sorry, for some reason I’m not understanding.

This:
https://jsfiddle.net/9kap56xw/

        const defaultOptions = defaults.playerOptions;
        const playerOptions = Object.assign({}, defaultOptions, settings);
        players.push(new YT.Player(video, playerOptions));
    }

next jslint issues

1 Like

There are several issues in that section of code that need to be dealt with.

First off, the video.dataset.id shouldn’t be used unless no videoIds are given to the addPlayer function.

We can use a default parameter value for the function parameter videoIds, so that video.dataset.id is used as the default value.

1 Like

What do I do first.

I’ve only said what you should do first. We’ll move on to what to do next after you’ve achieved this first thing.

What you do first is to add a default parameter to the videoIds parameter. That default needs to be video.dataset.id

Isn’t that done already?
https://jsfiddle.net/9kap56xw/

  function addPlayer(video, settings, videoIds) {
        const videoId = !Array.isArray(videoIds) && videoIds;
        const playlist = Array.isArray(videoIds) && videoIds;
        const defaults = {
            playerOptions: {
                events: {
                    "onReady": onPlayerReady
                },
                host: "https://www.youtube-nocookie.com",
                videoId: video.dataset.id
            }
        };
        const defaultOptions = defaults.playerOptions;
        const playerOptions = Object.assign({}, defaultOptions, settings);
        players.push(new YT.Player(video, playerOptions));
    }

No the default hasn’t been specified yet, as can be plainly seen in the above code.

You may need to read up again on how to set default parameter values

I thought all that was needed was this: video.dataset.id

I don’t know what these numbers mean and everything.


function f (x, y = 7, z = 42) {
    return x + y + z
}
f(1) === 50

Those are examples of giving the y parameter a default value of 7, and of giving the z parameter a default value of 42.

In your case, you should update your function parameters so that videoIds parameter is given a default value of video.dataset.id

value = number

What number?

You just pick any number?

It’s just in the example that a number was used. It doesn’t have to be a number, it can be anything.
In this case the default for the videoIds parameter needs to be video.dataset.id

I don’t know what to do with this, and where to place it in the code.

function f (x, y = 7, z = 42) {
    return x + y + z
}
f(1) === 50

Does it go below this?

function addPlayer(video, settings, videoIds) {
        const videoId = !Array.isArray(videoIds) && videoIds;
        const playlist = Array.isArray(videoIds) && videoIds;
        const defaults = {
            playerOptions: {
                events: {
                    "onReady": onPlayerReady
                },
                host: "https://www.youtube-nocookie.com",
                videoId: video.dataset.id
            }
        };
        const defaultOptions = defaults.playerOptions;
        const playerOptions = Object.assign({}, defaultOptions, settings);
        players.push(new YT.Player(video, playerOptions));
    }

Is function f being given a name?

or is it staying f?

Like that?

function addPlayer(video, settings, videoIds) {
        const videoId = !Array.isArray(videoIds) && videoIds;
        const playlist = Array.isArray(videoIds) && videoIds;
        const defaults = {
            playerOptions: {
                events: {
                    "onReady": onPlayerReady
                },
                host: "https://www.youtube-nocookie.com",
                videoId: video.dataset.id
            }
        };
        const defaultOptions = defaults.playerOptions;
        const playerOptions = Object.assign({}, defaultOptions, settings);
        players.push(new YT.Player(video, playerOptions));
    }
function f (x, y = 7, z = 42) {
    return x + y + z
}
f(1) === 50

Would Overloads be better to use?

you should update your function parameters so that videoIds parameter is given a default value of video.dataset.id

What does that mean?

Also, am I giving the function a name?

function f (x, y = 7, z = 42) {
    return x + y + z
}
f(1) === 50

Here is the line that I am instructing you to update.

function addPlayer(video, settings, videoIds) {

You’ve seen several examples of default parameters being specified for function parameters.

What I mean is to for you to update the videoIds function parameter, so that a default value of video.dataset.id is specified for that videoIds parameter.

1 Like

this:
https://jsfiddle.net/a39qLu8z/

    function addPlayer(video, settings, a) {
        const videoId = !Array.isArray(a) && a;
        const playlist = Array.isArray(a) && a;

No not that.

You’ve seen from http://es6-features.org/#DefaultParameterValues examples of providing default parameters values. In those examples there are two default parameters that are given, those being 7 and 42.

With the function addPlayer(video, settings, videoIds) { line the default parameter that you are being asked to do is video.dataset.id for the videoIds parameter.