Converting the inline javascript to pure javascript, how would this be done?


Your code does nothing with it, so yes it is useless.


You removed this:
player =

From here:
new YT.Player(document.querySelector

That part was useless too?


That’s right, for nothing is being done with player.


Which way is better?


    window.onYouTubePlayerAPIReady = function () {
        new YT.Player("player", {


   window.onYouTubePlayerAPIReady = function () {
    window.player = new window.YT.Player ("player", {

I was reading this:


You’re doing nothing with player, so assigning it as a global variable is only making things worse.

That is not a challenge for you to find something to do with it either. :slight_smile:


ok, it was just something I stumbled on.


Is it better to keep this stuff in the iframe, or the javascript?

       videoId: 'M7lc1UVf-VE',
      playerVars: {
        autoplay: 0,
        loop: 0,
        controls: 1,
        showinfo: 0,
        autohide: 0,
        rel: 0,
        iv_load_policy: 3,
        cc_load_policy: 0,
        fs: 0,
        disablekb: 1,


JavaScript is a better place for that, especially when it comes to updating the information, such as with the autoplay.

Only the information that varies from the default settings should be shown.


Meaning what? As an example.

I also have a question:

Which is better to use?
Is one way more efficient than the other?

  playerVars: {
        autoplay: 1,



function onPlayerReady(event) {
    const youtubePlayer =;


Well, when the text color is black, you shouldn’t use a style that sets the text color to black until you need to. There are thousands of default settings and listing all of the defaults in your code, distracts from the information that is more important.

Efficiency of human brain power is the much more vital consideration, than nanoseconds of computer power.

The second example with playVideo() is the preferable one, as it more clearly expresses the intention of what you want to achieve.


Believe it or not, there’s a big difference.

This one starts rapidly.

  playerVars: {
        autoplay: 1,


This one stops then goes.



Try taking the scripts off the “onload” load type (which is bloody slow), and to the nowrap bottom of body, one instead.

By the way, what are you measuring between them?


What do you mean?


Where the JavaScript section says “JavaScript + No Library” - click that.


I just threw both code in here:

Hit enter a bunch of times.

I don’t think I should be able to see the play button if it’s on auto start.



If the play button is viewable or not.

The first thing you see should be this:

  playerVars: {
        autoplay: 1,


This is something I just noticed recently.

When you double, triple click it goes into fullscreen mode.

This one: div tag

This one: iframe

And this one: div tag

Doesn’t happen with this one: iframe

or even this: iframe
<iframe width="518" height="291" src="" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

How come, and is there a specific way that can be controlled?


I think that it has something to do with the iframe not being in allow-presentation mode. I give up bashing my head against that one.

If autoplay works, then that’s the one to go for.


That’s ok. See if you can figure out #58

I don’t understand why certain ones allow full screen, and then others don’t, and how that can be controlled.


WTF’s a double triple click?!?!?