Solucio classe text

De wikiserver
La revisió el 21:54, 13 nov 2014 per Jnoguera (Discussió | contribucions) (Es crea la pàgina amb «<source lang="java"> function text(){ var text= "cadena de caracters"; this.afegirCaracter=function(caracter) { return text+=""+caracter; } this.contarVocals=functi…».)
(dif) ← Versió més antiga | Versió actual (dif) | Versió més nova → (dif)
Dreceres ràpides: navegació, cerca
function text(){

var text= "cadena de caracters";

this.afegirCaracter=function(caracter)
{
	return text+=""+caracter;
}


this.contarVocals=function()
{
var cont=0;
var texto=text.split("");
for (var i = texto.length - 1; i >= 0; i--) {
	if(texto[i]=='a' ||texto[i]=='e'|| texto[i]=='i' ||texto[i]=='o' ||texto[i]=='u'){
		cont++;
	}
};

return cont;
}

this.mostrarText=function()
{
	console.log(text);
}
}




var texto= new text();
texto.afegirCaracter("a");
texto.contarVocals();
texto.mostrarText();