Solucio Yahoo rellotge
De wikiserver
La revisió el 19:14, 13 nov 2014 per Jnoguera (Discussió | contribucions)
SOLUCIÓ YAHOO
function Yahoo(){
var numeros = "";
this.seguent = function(numeros){
switch(numeros){
case "cero":
return "un";
break;
case "un":
return "dos";
break;
case "dos":
return "tres";
break;
case "tres":
return "quatre";
break;
case "quatre":
return "molts";
break;
case "molts":
return "molts";
break;
case "desconegut":
return "desconegut";
break;
default:
return "desconegut";
}//cerrar switch
}; //cerrar this.seguent
this.suma = function(){
var numero = "";
var x = "";
if(arguments.length==0){
return "desconegut";
}
else if(arguments.length==1){
return arguments[0];
}
else{
numero = arguments[0];
x = arguments[1];
switch(numero){
case "cero":
return this.suma(x);
break;
case "un":
return this.seguent(x);
break;
case "dos":
return this.seguent(this.seguent(x));
break;
case "tres":
return this.seguent(this.seguent(this.seguent(x)));
break;
case "quatre":
return this.seguent(this.seguent(this.seguent(this.seguent(x))));
break;
case "molts":
return "molts";
break;
case "desconegut":
return "desconegut";
break;
default:
return "desconegut";
}//cerrar switch
} //cerrar else
}; //cerrar this.suma
/*Podemos sustituir la función de sumar sobre cargada por esta otra*/
function afegirMetode(objecte, nom, funcio){
var old = objecte[nom];
objecte[nom] = function(){
if(funcio.length == arguments.length)
return funcio.apply(this, arguments);
else if (typeof old == 'function')
return old.apply(this, arguments);
};
}
afegirMetode(this, "suma", function(){
return "desconegut";
});
afegirMetode(this, "suma", function(x){
return arguments[0];
});
afegirMetode(this, "suma", function(x){
return arguments[0];
});
afegirMetode(this, "suma", function(numero,x){
switch(numero){
case "cero":
return this.suma(x);
break;
case "un":
return this.seguent(x);
break;
case "dos":
return this.seguent(this.seguent(x));
break;
case "tres":
return this.seguent(this.seguent(this.seguent(x)));
break;
case "quatre":
return this.seguent(this.seguent(this.seguent(this.seguent(x))));
break;
case "molts":
return "molts";
break;
case "desconegut":
return "desconegut";
break;
default:
return "desconegut";
}
});
*/
} //cerrar yahoo
var yahoo1 = new Yahoo();
alert(yahoo1.seguent("desconegut"));
alert(yahoo1.seguent("cero"));
alert(yahoo1.seguent("un"));
alert(yahoo1.seguent("dos"));
alert(yahoo1.seguent("tres"));
alert(yahoo1.seguent("quatre"));
alert(yahoo1.seguent("molts"));
alert(yahoo1.seguent("seis"));
alert(yahoo1.suma());
alert(yahoo1.suma("un"));
alert(yahoo1.suma("cero","dos"));
alert(yahoo1.suma("quatre","dos"));
alert(yahoo1.suma("un","dos"));
alert(yahoo1.suma("desconegut","tres"));
alert(yahoo1.suma("cero","un"));
alert(yahoo1.suma("quatre","cero"));
alert(yahoo1.suma("quatre","un"));
alert(yahoo1.suma("tres","un"));
alert(yahoo1.suma("tres","cero"));
alert(yahoo1.suma("tres","dos"));
alert(yahoo1.suma("un","desconegut"));
SOLUCIO RELLOTGE
function Rellotge(){
var rellotge;
var rellotgeSec;
var tempsFun = 0;
this.ContructorRellotge = function(){
rellotge = new Date();
;
this.GetTime = function(){
rellotgeSec = new Date();
var timeMili = rellotgeSec.getTime() - rellotge.getTime();
var seg = timeMili / 1000;
return tempsFun + seg;
this.StopTime = function(){
tempsFun = this.GetTime();
rellotge = null;
};
this.StartTime = function(){
rellotge = new Date();
};
this.setFunctionOnTime =function(time,function){};
this.Execute = function(){};
}
var rellotge = new Rellotge();
rellotge.ConstructorRellotge();
alert(rellotge.GetTime());