<input type="text" id="producto">
<input type="button" onclick="comprar()" id="compra" value="Comprar">
<div id="cesta"></div>
var cesta = [];
function comprar() {
var producto = document.getElementById('producto').value;
if (producto.trim() !== "" && cesta.indexOf(producto) === -1) {
cesta.push(producto);
mostrar(cesta);
} else {
alert("Producto incorrecto o repetido");
}
}
function mostrar(cesta) {
var resultado = document.getElementById('cesta');
resultado.innerHTML = "";
for (var i = 0; i < cesta.length; i++) {
resultado.innerHTML += "<p>" + i + ".- " + cesta[i] + "</p>";
}
}