I am using the following for a different picture to show up every day....
<script language="JavaS cript">
<!--
function adspic() {
var mydate=new Date()
var day=mydate.getD ay()
var month=mydate.ge tMonth()
var daym=mydate.get Date()
if (daym<10)
daym="0"+daym
var adspicarray=new Array("ads/images/kilt.jpg",
"ads/images/kilt.jpg",
"ads/images/kilt.jpg",
"ads/images/apronandcase.jp g",
"ads/images/kilt.jpg",
"ads/images/apronandcase.jp g",
"ads/images/apronandcase.jp g")
document.write( "<p align='right'>< img src = '" + adspicarray[day] +
"'/>")}
// -->
</script>
Question (1)
How do I do it so that it is random??
Question (2)
How do i make it so that [day] can be used in other functions (currently i
use the same 'var' sequence in each function 15 1463
> How do I do it so that it is random??
It will be something like the following untested code.
<script type='text/javascript'>
function adspic() {
var adspicarray=["ads/images/kilt.jpg",
"ads/images/kilt.jpg",
"ads/images/kilt.jpg",
"ads/images/apronandcase.jp g",
"ads/images/kilt.jpg",
"ads/images/apronandcase.jp g",
"ads/images/apronandcase.jp g"];
document.write( "<p align='right'>< img src = '" +
adspicarray[Math.floor(7*Ma th.random())] +"'/>");
}
</script>
Don't bother with the language attribute it is deprecated. Use they
type attribute instead. Also the <!----> is not necessary anymore
apparently. Also don't forget semi-colons at the end of your
statements. Also you can use array literal notation instead of new
Array(). Try putting your orignial code in http://www.jslint.com for
suggestions on improving syntax.
Peter
JimK wrote: var day = Math.round(Math .random() * 5)
day is variable of the day of the week (0 = Sunday - 6 = Saturday).
With this random number generation you will never generate a 6. Also 0
and 5 will occur with half the frequency of 1,2,3,4.
Peter
JimK wrote: var day = Math.round(Math .random() * 6) // 6 images
day is variable of the day of the week (0 = Sunday - 6 = Saturday).
Now pictures 0 and 6 will appear with half the frequency of days
1,2,3,4,5
(0-0.5) --> 0
[0.5-1.5) --> 1
[1.5-2.5) --> 2
[2.5-3.5) --> 3
[3.5-4.5) --> 4
[4.5-5.5) --> 5
[5.5-6) --> 6 pe**********@gm ail.com said the following on 5/27/2006 1:52 AM: How do I do it so that it is random?? It will be something like the following untested code.
<script type='text/javascript'>
function adspic() { var adspicarray=["ads/images/kilt.jpg", "ads/images/kilt.jpg", "ads/images/kilt.jpg", "ads/images/apronandcase.jp g", "ads/images/kilt.jpg", "ads/images/apronandcase.jp g", "ads/images/apronandcase.jp g"];
document.write( "<p align='right'>< img src = '" + adspicarray[Math.floor(7*Ma th.random())] +"'/>");
adspicarray[Math.floor(adsp icarray.length* Math.random())]
Also don't forget semi-colons at the end of your statements.
Unless you know where they make a difference, you are generally better
off without trailing semicolons than with them. They are optional.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
JimK said the following on 5/27/2006 2:44 AM: On 26 May 2006 23:06:59 -0700, pe**********@gm ail.com wrote:
JimK wrote: var day = Math.round(Math .random() * 5)
day is variable of the day of the week (0 = Sunday - 6 = Saturday). With this random number generation you will never generate a 6. Also 0 and 5 will occur with half the frequency of 1,2,3,4.
Peter
Your right, took me a minute to figure out why. I was thinking about using Math.floor. I mis-counted the images in the array which I corrected
Instead of hard coding the images, use the arrayName.lengt h property and
then all it takes to add images is another entry into the array.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
So now how do I build the Var in so that it can be used in multiple
functions as I currently type the same code into each individual function
"Prophet" <M_*****@hotmai l.com> wrote in message
news:qdRdg.1057 $kK6.1032@edtnp s89... I am using the following for a different picture to show up every day....
<script language="JavaS cript"> <!-- function adspic() {
var mydate=new Date() var day=mydate.getD ay() var month=mydate.ge tMonth() var daym=mydate.get Date() if (daym<10) daym="0"+daym var adspicarray=new Array("ads/images/kilt.jpg", "ads/images/kilt.jpg", "ads/images/kilt.jpg", "ads/images/apronandcase.jp g", "ads/images/kilt.jpg", "ads/images/apronandcase.jp g", "ads/images/apronandcase.jp g")
document.write( "<p align='right'>< img src = '" + adspicarray[day] + "'/>")} // --> </script>
Question (1) How do I do it so that it is random??
Question (2) How do i make it so that [day] can be used in other functions (currently i use the same 'var' sequence in each function
JRS: In article <h9************ *************** *****@4ax.com>, dated
Sat, 27 May 2006 05:59:06 remote, seen in news:comp.lang. javascript,
JimK <1a****@gmail.c om> posted :
var day = Math.round(Math .random() * 5)
Reading the newsgroup FAQ *before* giving "advice" may help you to give
an illusion of competence.
R = Math.random()*5 |0
<FAQENTRY>
The FAQ has AFAICS no example of any of the single-character logical
operators; one could be placed in 4.22.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
JimK <1a****@gmail.c om> writes: ?? for you. Far as I know JS has no way to work with binary numbers like 00000000b directly, is this correct?
There is no way to specify that a number literal should be read as
an integer, and not a floating point number.
However, some operations implicitly convert their arguments to
a 32-bit integer. These are mainly the bit-operations: bitwise and,
bitwise or, bitwise xor, and the shifts.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen wrote: There is no way to specify that a number literal should be read as an integer, and not a floating point number. However, some operations implicitly convert their arguments to a 32-bit integer. These are mainly the bit-operations: bitwise and, bitwise or, bitwise xor, and the shifts.
Would it lead to implications if used in the reverse order?
0|510
In such case it could be used as a pseudo-allocator to use together
with say 0x1FE and 0776 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: raver2046 |
last post by:
hello,
How to have a global var in python ?
thank you.
raver2046
http://raver2046.ath.cx
|
by: rlo |
last post by:
use the next script:
var answers0 = new Array(
(answer11),
(answer12),
(answer13),
(answer14) );
question= new geefVraag( 0,
'question1', oke1-1, answers0);
feedback= new Array(
|
by: Maja |
last post by:
Greetings,
/var/adm/wtmp files were getting out of hand
and I wanted to filter the file rather than zeroing it out.
I found some code that would only keep the last x days
but it required creating a temporary file in /tmp
and then copying it back to /var/adm. I rewrote the code
to load the contents of the wtmp file into memory and then
write the filtered records in memory directly back to /var/adm/wtmp,
eliminating the need for a...
|
by: Thierry Loiseau |
last post by:
Hello all,
and Happy end year 2005 !
Well, I would like to obtain a list of all JavaScript var statement,
With "for...in" perharps ?
That is bellow my recent test here, but the problem is to management
theses :-((( I must to declare and use all variable with this scheme :
|
by: overdalsveien |
last post by:
hi
This is probably elementary, but since my 'Dear Watson' is not present
I hope you folks can help me::
---------------------------
var dag = date1.getDate();
document.getElementById("selDay1").innerHTML =
makeRequest('test.php?d=1');
-----------------------------------------------
| |
by: vlsidesign |
last post by:
If I have a "for" loop like this:
for (i = 0; i < 10; i++)
or like this
for (i = 0; i < 10; ++i)
both of the "for" loops will function the same. I also noticed if I use
a variable called j within the "for" loop body, and put these statement
in the "for" loop body like this:
printf("j var is: %d\n", ++j);
printf("j var is: %d\n", j++);
In the first statement, "j" increments first, and then prints "j"
|
by: Rainy |
last post by:
I have a stylistic question. In most languages words in var. name are
separated by underscores or cap letters, resulting in var names like
var_name, VarName and varName. I don't like that very much because all
3 ways of naming look bad and/or hard to type. From what I understand,
scheme can have variables like var-name. I'm curious about reasons
that python chose to disallow this. Another question I have is what
other languages allow this...
|
by: DL |
last post by:
For instance,
function addNew(i) {
var 'element'&i
...
}
If possible, how to?
Thanks.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |