So, I'm starting with JavaScript and got an assignment with a randomizer-ish and goes like this:
There are two usernames reserved, user1 and user2, whenever they put their name on the prompt(), they get a message that they won a car(the car is random).
I made it to the part where the user gets the message, but the problem is, I have to show an image of the car and the message, and I don't know how to do that.
Any advice on how to solve that?
var username = prompt("Hello, who are you?");
var cars = [
"car1",
"car2",
"car3"
];
if (username === "user1") {
var randomCar = Math.floor(Math.random() * cars.length);
var car = cars[randomCar];
document.write("<h1>Congratulations " + username + " you won a " + car + "!</h1>");
} else {
if (username === "user2") {
var randomCar = Math.floor(Math.random() * cars.length);
var car = cars[randomCar];
document.write("<h1>Congratulations " + username + " you won a " + car + "!</h1>");
} else {
document.write("<h1>Sorry " + username + " you didnt won this time." + "</h1>");
}
}