How is condition player.src != ""; supposed to be written?

I got these in jslint:

I got this:
Expected ‘!==’ and instead saw ‘!=’.
player.src != "";

Then: after I changed it I got this.
Unexpected expression ‘!==’ in statement position.
player.src !== "";

    sent.addEventListener("click", function() {
        player.src = value.value;
        player.src != "";
        player.volume = 1.0;
        playPauseIcon(true);
    });

jsfiddle:

Look up the difference between assignment and comparison.

1 Like

jslint is telling me this is wrong:
player.src != "";

And this is wrong:
player.src !== "";

Yes and Yes.

In your own words, what would be your definitions of “assignment” and of “comparison” as you understand them?

I don’t even know why it was added to the code to begin with.
It works the same way without it even in it.

Maybe this condition doesn’t even exist.
player.src != "";
player.src !== "";

I guess it was supposed to help in:

Disabling the play/pause button until there is a connection with the audio.

It looks like it’s the condition from an if statement that has since been removed.

I was suggested to use this,
player.src !== ""

I added it in, but I never thought to remove it until realizing it’s not doing anything in the code.

Which post made that suggestion?

This looks to be the post in which where you were told to add it.

That piece of code cannot work all by itself. A condition is a part of an if statement. Here is how an if statement is structured.

if (condition) {
  // code to run if condition is true
} else {
  // run some other code instead
}

It is in the condition location, that the person was recommending that you use that snippet of code.

I recommend that you have a read of the Making decisions in your code — conditionals article to learn more about them.

That would look like this, but I don’t understand what it’s supposed to do.

sent.addEventListener("click", function() {
            player.src = value.value;

            if (player.src !== "") {

            } else {

            }

That would be to do this?
The Play button would only change to the pause button if the audio was working.

Is undefined ever === an empty string?

Are input values undefined?

This will help with that question:

submit doesn’t return anything, which is why the value is undefined. You want to get the value of the input element. The best way to do that is to assign it an id

No, that one doesn’t look to be at all relevant.

Input fields don’t have undefined values.

If you get undefined, then the code cannot find the input field.
If you get “” from the input field, that’s an empty string that represents that the field has nothing in it.

Does this code:

sent.addEventListener("click", function() {
            player.src = value.value;

            if (player.src !== "") {

            } else {

            }

Do this, or no? Does it have anything to do with it?
The Play button would only change to the pause button if the audio was working.

If not, then I will try and think of a different way this can be done.

I swore off helping you with that code due to terms of use and permission issues.
I’ll help you with basic concepts relating to that code, but not otherwise.

Someone else must help you further.

It should be changed to oncanplay instead of onloadstart, and then it works as it should.

Play button changes from Play to Pause when the audio link is valid.

Play button does not change from Play to Pause when the audio link is not valid.

player.oncanplay = function () {
    if (value.value !== "") {
        canPlay = true;
        playPauseIcon(true);
    }
};

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oncanplay

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.