Can someone explain what am I missing? Uncaught ReferenceError

I am not posting this so someone can solve it for me, but becasue I am learning without much guidance,and I am sure I’ve skipped something that I should have known before I start practicing arrays and objects.(can you give me a hint to what I should learn?)
Every variable is globaly defined at the beggining of the code, so I have no idea why it’s givin this error.

Thats the error I am getting: Uncaught ReferenceError: printNames is not defined
This is my code:
HTML

<html>

    <head>
        <title>Player Screen</title>
        <meta name="Description" content="Players info">
        <meta charset="UTF-8">
        <link rel="stylesheet" href="style.css">
        <script scr="script.js"></script>
    </head>

    <body>
        
        <div class="joined-players">
            <div class="player-card" onclick="printNames();">
                <div class="player-details">
                    <p class="player-name"></p>
                    <p class="player-score"></p>
                </div>
                <div class="player-img" onclick="changePlayerDetails();"></div>
            </div>
        </div>

    </body>

</html>

and js

function Player(name, score)
{
    this.name = name;
    this.score = score
}

var players = new Array();
players.push(new Player("Player Array 1", 500));
players.push(new Player("Player Array 2", 20));


function printNames()
{
    for(var i = 0; i != players.length; i++)
    {
        console.log(players[i].name);
        console.log(players[i].score);
    }
}

function changePlayerDetails()
{
    var playerName = document.getElementsByClassName("player-name");
    var playerScore = document.getElementsByClassName("player-score");

    playerName.value = players[0].name;
    playerScore.value = players[0].score;

}

Remove the ; from the onclick.

Also I would advice you to use eventlisteners over onclicks in your HTML.

still the same error. ):

It’s working for me on codepen.
Try adding defer to the script-tag or moving it before your closing body-tag. Sometimes those things can make things mess up.

Edit:
Found it! :stuck_out_tongue:
<script scr="script.js"></script>
should be src not scr

3 Likes

Thank you man! Jesus I just hate these small little typos… Before typing lenght instead of length was giving me so much troubles, and its practically invisible :smiley: