StringManolo

Suma

Apr 20th, 2020
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. </head>
  6. <body>
  7. <script>
  8. function Sumar(veces) {
  9.   var i = 0;
  10.   var numeroTotal = 0;
  11.   var numeroActual = 0;
  12.  
  13.   while(i < veces) {
  14.    numeroActual = prompt("Pon el número");
  15.    numeroTotal += +numeroActual;
  16.    ++i;
  17.  }
  18.  
  19.  return numeroTotal;
  20. }
  21.  
  22.  
  23.  
  24. var op = prompt("1. Sumar 2\n2.Sumar 7\n3.Sumar 30\n0.Salir");
  25. var res = 0;
  26.  
  27. if (op == 1) {
  28.  res = Sumar(2);
  29. }
  30.  
  31. if (op == 2) {
  32.  res = Sumar(7);
  33. }
  34.  
  35. if (op == 3) {
  36.  res = Sumar(30);
  37. }
  38.  
  39. alert("El resultado de tus sumas es " + res);
  40.  
  41. </script>
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment