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

How is this supposed to be written?

I got these in jslint

Expected ‘!==’ and instead saw ‘!=’.

player.src != "";

Then, after I changed it I got this.

Unexpected expression ‘!==’ in statement position.

player.src !== "";

Code:
https://jsfiddle.net/vhgL96se/50/

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

jsfiddle:

The linter is asking you to prefer a strict equality check to the loose one, which in general is always preferred.

About the second one, the program is wandering exactly why you are writing an expression without doing nothing with it.

Inside the function you are assigning to player.src -> value.value

    player.src = value.value;

And then asking to check if player.src is not “empty string”

player.src != "";

What exactly is the program supposed to do with this check?

Do you want to do something based on this condition?

if(player.src !=== "") do stuff?
1 Like

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

How would it be written then?

Here’s a stream link:
http://hi5.1980s.fm/;

Then you want a condition based on the retuned value of that expression :+1:

How would that be written into the code?
https://jsfiddle.net/vhgL96se/50/

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

It’s a basic conditional flow control

sent.addEventListener("click", function() {
    player.src = value.value;
  
  // if src is not an empty string (change your check according to your needs)  
  if (player.src !== "") {
   console.log("src is not an empty sting")
  }

// if we reach here means that src is actually an empty string
console.log("src is an empty string")

});

EDIT:
my personal preference is in general to rule out and return early when the value is not the one I want, so for example

function alertName(name) {
 // fist I check that "name" is here, if not we return early
  if (!name) {
     return "you haven't supplied a name"
  }

// if reach here means that we can assume name is provided
alert("Hello, " + name)

}

Hope it helps :+1:
1 Like

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.

That’s what I was trying to accomplish.