come mostrare una stringa all'inverso?
poi...le lettere della stringa dovrebbero uscire con un'ordine casuale!
ciao![]()
come mostrare una stringa all'inverso?
poi...le lettere della stringa dovrebbero uscire con un'ordine casuale!
ciao![]()
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]
Va bene una csoa cosi`?codice:var strorg = "tua stringa"; // stinga di input (viene modificata) var strinv = ""; // stringa invertita var strrnd = ""; // stringa anagrammata random for (var i=strorg.length; i>0; i--) { // inversione strinv += strorg.substr(i-1,1); } while ((var m = strorg.length) > 0) { // randomizzaz. var j = Math.floor(Math.rand()*m); strrnd += strorg.substr[j,1]; strorg = strorg.substr(0,j) + strorg.substr(j+1); alert ("controllo: strorg="+strorg); // da togliere dopo il debug) }
Non la ho provata: fallo tu per me.
Ciao
Michele
Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
No domande tecniche in messaggi privati
mi spieghi cosa fanno?...le provo subito![]()
grazie
![]()
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]
no...non funziona tutto....mi da errore qui:
function random(strorg)
{
var strrnd = "";
while ((var m = strorg.length) > 0) {
var j = Math.floor(Math.rand()*m);
-----> strrnd += strorg.substr[j,1];
strorg = strorg.substr(0,j) + strorg.substr(j+1);
alert ("controllo: strorg="+strorg);
}
document.f.casuale.value=strrnd
}
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]
Ecco le prove che devi fare:
1. togliere la funzione random (in pratica tutto il ciclo while), per vedere se il resto funziona.
2. dirmi anche che errore ti da`
3. inserire un alert cosi`:Ciaocodice:while ((var m = strorg.length) > 0) { // randomizzaz. var j = Math.floor(Math.rand()*m); alert ("j="+j+" car="+strorg.substr[j,1]); strrnd += strorg.substr[j,1]; strorg = strorg.substr(0,j) + strorg.substr(j+1); alert ("controllo: strorg="+strorg); // da togliere dopo il debug) }
Michele
Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
No domande tecniche in messaggi privati
č solo la funzione di random ke non vā...
dā errore di sintassi e non esegue proprio lo script...ora ti posto tutto...
codice:<script language="JavaScript"> var strinv = ""; function elabora() { parola=document.f.stringa.value document.f.lunghezza.value=document.f.stringa.value.length inverso(parola) random(parola) } function inverso(word) { for (var i=word.length; i>0; i--) { // inversione strinv += word.substr(i-1,1); } document.f.inversa.value=strinv } function random(strorg) { var strrnd="" while ((var m = strorg.length) > 0) { // randomizzaz. var j = Math.floor(Math.rand()*m); alert ("j="+j+" car="+strorg.substr[j,1]); strrnd += strorg.substr[j,1]; strorg = strorg.substr(0,j) + strorg.substr(j+1); alert ("controllo: strorg="+strorg); // da togliere dopo il debug) } document.f.casuale.value=strrnd } </script>![]()
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]
Ha pure ragione. Il metodo si chiama Math.random() .
Per riferimento
E dato che random e` una funzione intrerna, magari non usarla come nome di funzione.
Scusa
Ciao
Michele
Nuova politica di maggiore severita` sui titoli delle discussioni: (ri)leggete il regolamento
No domande tecniche in messaggi privati
no...mi dā errore ancora su quella riga modificata...
codice:while ((var m = strorg.length) > 0) { var j = Math.floor(Math.random()*m); alert ("j="+j+" car="+strorg.substr[j,1]); strrnd += strorg.substr[j,1]; strorg = strorg.substr(0,j) + strorg.substr(j+1); alert ("controllo: strorg="+strorg); // da togliere dopo il debug)
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]
prova a mettere le parentesi tonde invece delle quadre dove c'č substr
ora l'errore č qui...
strrnd += strorg.substr(j,1);
[ SimplyMepis 8 ]Copyleft
www.mepisitalia.org IL SITO ITALIANO UFFICIALE DI MEPIS
www.salentomovida.it LA MOVIDA DEL SALENTO HA UN NUOVO PUNTO D'INCONTRO SUL WEB
[ SUD SOUND SYSTEM MINA FUECU INTRA ALLU SALENTU ]