My question might look simple, I've searched the web and found no answer.
I had the browser run my <h1>
HTML tag first, and then do the JavaScript file. But the result is that JavaScript is blocking my HTML code and runs the prompt()
first.
I hope you can help me find a solution and learn something new.
This is my HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Keyless Car</title>
</head>
<body>
<h1>Hello there, this is your Keyless Car.</h1>
<script type="text/javascript" src="Keyless car.js"></script>
</body>
</html>
This is my JavaScript code:
var age = prompt("How old are you?");
if (Number(age) < 18){
alert("Sorry, you are too young to drive this car. Powering off");
}
else if (Number(age) === 18){
alert("Congratulations on your first year of driving. Enjoy the ride!");
}
else{
alert("Powering On. Enjoy the ride!");
}
I tried putting the <script>
in the <head>
, at the end of the <body>
, after the <body>
, and also after the </html>
, but the same issue is still popping up.