I have an error binding the textbox to the variable t of js. I don't know what the problem is, if the link with the button works. the problem is in line 9 of the code js
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>cajero ero</title> </head> <body> <p> <img src="cajero.gif" alt=""> </p> <input type="text" name="" id="dinero"> <input type="button" name="cosa" value="extraer" id="cosaa"> <script type="text/javascript" src="cajero.js"></script> </body> </html>
class Billete {// constructor de billeres nombre y cantidad constructor(v,c){ this.valor=v; //valor del billete this.cantidad=c;//cantidad de billetes } } function entregarDinero (){ var t=document.getElementById("dinero"); var dinero= parseInt(t.valor); for (var bi of caja ){ // carga cada elemento de la variable caja a bi en cada ciclo if (dinero >0){//comprueba que la cantidad pedida sea mayor que 0 div =Math.floor(dinero /bi.valor); //hace la division y la redondea por debajo if (div > bi.cantidad){ papeles= bi.cantidad; } else{ papeles= div; entregar.push(new Billete(bi.valor, papeles) ); dinero=dinero-(bi.valor*papeles); } } } if (dinero > 0){ console.log("no tengo mas dinero "); } console.log(entregar); } var caja=[];// caja de nuestro cajero automatico Array donde entaran los billetes var entregar=[]; caja.push (new Billete (50,3)); caja.push (new Billete (20,2)); caja.push (new Billete (10,2)); //caja.push le agrega contenido a la variable caja // new Billete crea el objeto billete con los parametros var dinero=2100; var div=0; var papeles=0; var b = document.getElementById('cosaa'); b.addEventListener("click", entregarDinero);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)