lundi 5 mars 2018

multiple actions from javascript if

I can't seem to find the documentation that discusses this, so I thought maybe someone on here could help. I want to write a javascript if/else function that triggers multiple events. My code is a little rough, but I think it should look like:

<script>
function getFruit() {
var x = document.getElementById("myinput").value;
var score;
var picture;

if (x === "Apple") {
   score = "A" || pciture = "http://exampple.com/assets/apple.jpg";
else (x === "Banana") {
   score = "B" || picture = "http://example.com/assets/banana.jpg";
}
document.getElementById("text").innerHTML = score;
document.getElementById("display").image.src = picture;
}
</script>

<input type="text" id="myinput">
<p id="text"></p>
<img id="display"></img>

Aucun commentaire:

Enregistrer un commentaire