Hello I am new to coding and I need some help with my javascript. Here's what I have to do. (I'd love an explanation along with the answer, I am genuinely trying to learn.) Here is what I need to do.
I need to display an image with the random car it chooses. (the options are bmw, Saab, and Maserati. if you win a bmw, there should be a picture of a bmw) I have no idea how to do this, I never worked with arrays.
Thank you so much for any help!
<script>
var username = prompt("Hello, who are you?");
var car = new Array("BMW", "Saab", "Maserati");
console.log(car);
if(username==="Chris") {
document.write("<h1>Hello " + username + " you won a " + car[1] + "!</h1>");
}else if(username === "Sasha") {
document.write("<h1>Hello " + username + " you won a " + car[1] + "!</h1>");
}
else {
document.write("<h1>Hello " + username + "!");
}
</script>