Diferència entre revisions de la pàgina «Solucio yahoo rellotge»
De wikiserver
(Es crea la pàgina amb «'''SOLUCIÓ YAHOO''' <source lang="java"> function Yahoo(){ var numeros = ""; this.seguent = function(numeros){ switch(numeros){ case "cero": return "u…».) |
|||
Línia 126: | Línia 126: | ||
alert(yahoo1.suma("tres","dos")); | alert(yahoo1.suma("tres","dos")); | ||
alert(yahoo1.suma("un","desconegut")); | alert(yahoo1.suma("un","desconegut")); | ||
+ | |||
+ | </source> | ||
+ | |||
+ | '''SOLUCIÓ RELLOTGE''' | ||
+ | |||
+ | <source lang="java"> | ||
+ | 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(); | ||
+ | }; | ||
+ | |||
+ | } | ||
+ | |||
+ | var rellotge = new Rellotge(); | ||
+ | rellotge.ConstructorRellotge(); | ||
+ | alert(rellotge.GetTime()); | ||
</source> | </source> |
Revisió de 14:00, 13 nov 2014
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
} //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"));
SOLUCIÓ 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();
};
}
var rellotge = new Rellotge();
rellotge.ConstructorRellotge();
alert(rellotge.GetTime());