HighDots Forums  

domanda matematica su Script

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss domanda matematica su Script in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
pierino
 
Posts: n/a

Default domanda matematica su Script - 01-08-2008 , 10:14 AM






dato questo script:
come potrei fare in modo da avere nella variabile "secondi" non un
numero intero ma comprensivo dei centesimi?

<script type="text/javascript">

function rnd_immagine(){
var now =new Date();
var secondi = now.getSeconds();
rnd_numero = Math.floor(secondi/1.5);
document.write('<img src="http://..' + rnd_numero +'.jpg">');
}
</script>

rigrazie da pierino



Reply With Quote
  #2  
Old   
Cristiano Larghi
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 10:27 AM






Il Tue, 08 Jan 2008 16:14:15 GMT, pierino ha scritto:

Quote:
come potrei fare in modo da avere nella variabile "secondi" non un
numero intero ma comprensivo dei centesimi?

var now =new Date();
var secondi = now.getSeconds();
... + now.getMilliseconds()/1000 ?

--
"E' l' ignoranza che crea l'intolleranza
di gente cieca e senza coscienza"
S.S.S.


Reply With Quote
  #3  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 10:37 AM



Così parlò Cristiano Larghi, alle ore 17.27.23 di martedì il 08/01/2008
Dopo Cristo


Quote:
Il Tue, 08 Jan 2008 16:14:15 GMT, pierino ha scritto:

come potrei fare in modo da avere nella variabile "secondi" non un
numero intero ma comprensivo dei centesimi?

var now =new Date();
var secondi = now.getSeconds();
... + now.getMilliseconds()/1000 ?
ma così è a millesimi vero?

quindi, può essere giusto così?

function rnd_immagine(){
var now =new Date();
var secondi = now.getSeconds();
var centesimi = now.getMilliseconds()/1000;
-----------------------------------------------

ma come fare ad implementarla in modo che venga esempio 10.55?

rnd_numero = Math.floor(secondi/1.5);
document.write('<img src="http://..' + rnd_numero +'.jpg">');

......




Reply With Quote
  #4  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 10:41 AM



Così parlò pierino, alle ore 17.37.33 di martedì il 08/01/2008 Dopo
Cristo


Quote:
Così parlò Cristiano Larghi, alle ore 17.27.23 di martedì il 08/01/2008 Dopo
Cristo

Il Tue, 08 Jan 2008 16:14:15 GMT, pierino ha scritto:

come potrei fare in modo da avere nella variabile "secondi" non un numero
intero ma comprensivo dei centesimi?

var now =new Date();
var secondi = now.getSeconds();
... + now.getMilliseconds()/1000 ?

ma così è a millesimi vero?

quindi, può essere giusto così?

function rnd_immagine(){
var now =new Date();
var secondi = now.getSeconds();
var centesimi = now.getMilliseconds()/1000;
-----------------------------------------------

ma come fare ad implementarla in modo che venga esempio 10.55?

rnd_numero = Math.floor(secondi/1.5);
document.write('<img src="http://..' + rnd_numero +'.jpg">');

.....
10.55 deve essere il risultato della variabile rnd_numero,
poi in document.write , dovrà essere un numero intero




Reply With Quote
  #5  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 11:01 AM



allora, ho modificato lo script.

<script type="text/javascript">

function rnd_immagine(){
var now = new Date();
var secondi = now.getMilliseconds()/1000 ;
rnd_numero = Math.floor(milliseconds/1.5);
intero = rnd_num(abs) ;
document.write('<img src="http://..' + intero +'.jpg">');
}
</script>

può andare bene così oppure ho sbagliato la funzione (abs)?

una cosa, ma "now.getMilliseconds()/1000" che valore da di preciso?



Reply With Quote
  #6  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 11:06 AM



Corretta la variabile
ho anche lasciato i millisec senza /1000.
-------------------

<script type="text/javascript">

function rnd_immagine()

{
var now = new Date();
var millisec = now.getMilliseconds();
rnd_numero = Math.floor(millisec/1.5);
intero = rnd_num(abs) ;
document.write('<img src="http://..' + intero +'.jpg">');
}

</script>

può andare ?



Reply With Quote
  #7  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 11:12 AM



Così parlò pierino, alle ore 18.06.41 di martedì il 08/01/2008 Dopo
Cristo


Quote:
Corretta la variabile
ho anche lasciato i millisec senza /1000.
-------------------

script type="text/javascript"

function rnd_immagine()

{
var now = new Date();
var millisec = now.getMilliseconds();
rnd_numero = Math.floor(millisec/1.5);
document.write('<img src="http://..' + rnd_numero +'.jpg">');
}

/script

può andare ?
intero non serve, Math.floor restituisce già un numero intero l'ho
tolta.




Reply With Quote
  #8  
Old   
pierino
 
Posts: n/a

Default Re: domanda matematica su Script TUTTAPOSTO - 01-08-2008 , 11:20 AM



definitiva (5.2631578) x 190 immagini (1000/190)

function rnd_immagine(){

var now =new Date();
var millisec = now.getMilliseconds();
rnd_numero = Math.floor(millisec/5.2631578);
document.write('<img src="http://...' + rnd_numero +'.jpg">');
}
//-->
</script>

grazie e scusate la mia ignoranza...



Reply With Quote
  #9  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: domanda matematica su Script - 01-08-2008 , 05:02 PM



In it.comp.lang.javascript messaggio <mn.44217d81b5cb80d1.60404 (AT) gmail (DOT) co
m>, 8 Jan 2008 16:37:33, pierino <pierino (AT) gmail (DOT) com> ha scritto:
Quote:
ma come fare ad implementarla in modo che venga esempio 10.55?

<URL:http://www.merlyn.demon.co.uk/js-round.htm> ff. ????

È una buona idea leggere il newsgroup c.l.j ed il relativo FAQ. Veda sotto.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.