Diferència entre revisions de la pàgina «Solucio michelin»

De wikiserver
Dreceres ràpides: navegació, cerca
 
Línia 1: Línia 1:
<source lang="java">
+
Fitxer menu.js:
var camarero1 = new camarero(0);
+
<source lang="javascript">
var camarero2 = new camarero(0);
+
var camSel = 1;
var cam="cama1";
+
var total1 = 0;
 +
var total2 = 0;
  
function camarero(saldo)           //función constructora donde se almacena el saldo
+
window.onload = function() {
{
+
     document.getElementById("c1").onclick = seleccionarCam;
     this.saldo = saldo;
+
     document.getElementById("c2").onclick = seleccionarCam;
 
+
     document.getElementById("1").onclick = seleccionTapa;
     this.afegirSou = function(saldo)
+
     document.getElementById("2").onclick = seleccionTapa;
     {
+
     document.getElementById("3").onclick = seleccionTapa;
        this.saldo += saldo;
+
     document.getElementById("4").onclick = seleccionTapa;
     }
 
      
 
     this.retornSou = function()
 
    {
 
        return this.saldo;
 
    }
 
 
}
 
}
  
 +
function seleccionarCam(evento) {
 +
    var e = evento || window.event;
  
function calcular(elEvento)
+
     camSel = e.currentTarget.value;
{
 
     var evento = elEvento || window.event;
 
 
 
 
 
                                                                //solució per a tres tapes
 
            if(evento.target.id=="tapa0") valor=5;          //també es possible obtindre id amb 'this.id'
 
            else if(evento.target.id=="tapa1") valor=4;
 
            else valor=3;
 
           
 
            (cam == "cama1") ? camarero1.afegirSou(valor) : camarero2.afegirSou(valor);
 
 
 
            document.getElementById("sou").innerHTML= "VENDES PEP: " +camarero1.retornSou()+"€  -- "+" VENDES JOSEP: "+camarero2.retornSou()+"€ ";
 
       
 
 
 
 
}
 
}
  
 +
function seleccionTapa(evento) {
 +
    var e = evento || window.event;
 +
    if (camSel == 1) {
 +
        total1 += parseInt(e.currentTarget.id);
 +
    }
 +
    else {
 +
        total2 += parseInt(e.currentTarget.id);
 +
    }
 +
    document.getElementById("info" + camSel).innerHTML += "<br>Tapa" +
 +
            e.currentTarget.id + ": " + e.currentTarget.id + "€";
 +
    document.getElementById("total" + camSel).innerHTML = (camSel==1)? total1 : total2;
  
function camareros(elEvento)
 
{
 
    var evento = elEvento || window.event;
 
 
    (this.id=="cama1")?cam="cama1":cam="cama2";
 
 
     
 
 
}
 
}
 
 
window.onload = function() {
 
 
 
    document.getElementById("tapa0").onclick = calcular;
 
    document.getElementById("tapa1").onclick = calcular;
 
    document.getElementById("tapa2").onclick = calcular;
 
    document.getElementById("cama1").onclick = camareros;
 
    document.getElementById("cama2").onclick = camareros;
 
 
}
 
 
 
</source>
 
</source>
  
 +
Fitxer index.html:
 
<source lang="html">
 
<source lang="html">
 
<html>
 
<html>
 
     <head>
 
     <head>
     
+
         <meta charset="UTF-8"/>
         <meta charset="UTF-8">
+
         <script type="text/javascript" src="js/menu.js"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
         <style type="text/css">
         <script type="text/javascript" src="tapes.js"></script>
+
            html
         <link rel="stylesheet" type="text/css" href="estilo.css">
+
            {
 +
                font-family: "courier new";
 +
            }
 +
        </style>
 
     </head>
 
     </head>
     <body>
+
     <body >
          
+
         <img id = "1" src="imagenes/1.png" alt="tapa 1" />
   
+
        <img id = "2" src="imagenes/2.png" alt="tapa 2"/>
            <img id="tapa0" src="./images/tapa1.jpg">
+
        <img id = "3" src="imagenes/3.png" alt="tapa 3"/>
            <img id="tapa1" src="./images/tapa2.jpg">
+
        <img id = "4" src="imagenes/4.png" alt="tapa 4"/>
            <img id="tapa2" src="./images/tapa3.jpg">
+
        <button id="c1" value="1">Camarero 1</button>
           
+
        <button id="c2" value="2">Camarero 2</button>
            <input id="cama1" type="button" value="CAMBRER 1">
+
        <div id="info1">Tapas servidas por el camarero1:</div>
            <input id="cama2" type="button" value="CAMBRER 2">
+
        <div id="total1"></div>
            <div id="sou"></div>
+
        <div id="info2">Tapas servidas por el camarero2:</div>
 +
        <div id="total2"></div>
 
     </body>
 
     </body>
 
</html>
 
</html>
 
</source>
 
</source>

Revisió de 19:23, 30 oct 2015

Fitxer menu.js:

var camSel = 1;
var total1 = 0;
var total2 = 0;

window.onload = function() {
    document.getElementById("c1").onclick = seleccionarCam;
    document.getElementById("c2").onclick = seleccionarCam;
    document.getElementById("1").onclick = seleccionTapa;
    document.getElementById("2").onclick = seleccionTapa;
    document.getElementById("3").onclick = seleccionTapa;
    document.getElementById("4").onclick = seleccionTapa;
}

function seleccionarCam(evento) {
    var e = evento || window.event;

    camSel = e.currentTarget.value;
}

function seleccionTapa(evento) {
    var e = evento || window.event;
    if (camSel == 1) {
        total1 += parseInt(e.currentTarget.id);
    }
    else {
        total2 += parseInt(e.currentTarget.id);
    }
    document.getElementById("info" + camSel).innerHTML += "<br>Tapa" +
            e.currentTarget.id + ": " + e.currentTarget.id + "€";
    document.getElementById("total" + camSel).innerHTML = (camSel==1)? total1 : total2;

}

Fitxer index.html:

<html>
    <head>
        <meta charset="UTF-8"/>
        <script type="text/javascript" src="js/menu.js"></script>
        <style type="text/css">
            html
            {
                font-family: "courier new";
            }
        </style>
    </head>
    <body >
        <img id = "1" src="imagenes/1.png" alt="tapa 1" />
        <img id = "2" src="imagenes/2.png" alt="tapa 2"/>
        <img id = "3" src="imagenes/3.png" alt="tapa 3"/>
        <img id = "4" src="imagenes/4.png" alt="tapa 4"/>
        <button id="c1" value="1">Camarero 1</button>
        <button id="c2" value="2">Camarero 2</button>
        <div id="info1">Tapas servidas por el camarero1:</div>
        <div id="total1"></div>
        <div id="info2">Tapas servidas por el camarero2:</div>
        <div id="total2"></div>
    </body>
</html>