Archie2033 Archie2033 - 26 days ago 7
HTML Question

What's wrong with this code(JavaScript, buttons, HTML)?

<!DOCTYPE html>
<html>
<head>
<title>Question 2</title>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
</head>
<body>
<button onClick="myFunction()">Alphabetical order</button>
<button onClick="countFunction">Count</button>

<p id="i"></p>
<p id="ii"></p>

<script>
var products = ["Printer", "Tablet", "Router", "Keyboard"];
document.getElementById("i").innerHTML = products;

function myFunction() {
products.sort();
document.getElementById("i").innerHTML = products;
}

function countFunction() {
document.getElementById("i").innerHTML = products.length;
}
</script>
</body>
</html>


I think it's just a spelling or formatting error. If you can change the code as little as possible while still fixing it I would appreciate it a lot. If you need any more details please just ask. I would be happy to provide as much information as I can to help you help me.

This is for my son - he loves traffic lights!

Answer

Modify these lines:

<button onClick="myFunction();">Alphabetical order</button>

<button onClick="countFunction();">Count</button>