Forum Moderators: coopster
1). script to print every even integer value between 1 and 20 inclusive,
2). use a for loop to print all integers betweeen 1 and 30 divisible by either 3 or 4. Modify the loop to count matches
b). use a while loop to print all numbers between 1 and 30 divisible by 3 and 4. Now midify the loop to count the matches.
3). Write a script to output a 10 line table where the rows alternate in color. Label each row with its number.
4). Write a script to display 8x8 chequered table, chess board!
if anyone could just complete one excercies i would be very greatful, ive just left it too late!
Thanks!
Come on Dan your having a laugh arnt you? :)
You could find most of what you need with Google, but the basis seems to be looping logic. These tutorials have some decent examples
[zorka.com...]
And this one, under looping covers a few of what you have to do
[w3schools.com...]
so this creates a list of all the numbers from 1 to 20! correct!
<?php
$i=1;
while($i<=20)
{
echo " . $i . "<br />";
$i++;
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
wonderful, no i need to do sumthing like this,
<?php
function OddOrEven($intNumber)
{
if ($intNumber % 2 == 0 )
{
echo "Your number is even<br>";
}
else
{
echo "Your number is odd<br>";
}
}
//test the function with 2 values 40 and 3
OddOrEven(1);
to...
OddOrEven(20);
?>
but without writing in all the numbers as OddorEven!
just a little help!
if ( ($number / 2) == trim($number /2) ) {
echo $number." is even<br>";
}
else
{
//echo "it is not even";
}
}
?>
i dont want to seem ungreatful, but this doesnt work it out puts all the numbers correctly but apparently there all even numbers and i dont understand where its going wrong?
dont think im grasping all this php malarky,
furthur questions that are listed above seem impossible,
print all integers between 1 and 3 divisible by 3 or 4,
and count the matches! yeh right
and...
print number between 1 and 30 divisible by 3 and 4?
and what about....
alternating row colours?
drawing back board! ;)
Basics of checker board with tables
[blinkinglights.org...]
The divisible by three make me think of something along the line of:
Divide by three, then do an if and see if the value is a whole number. If it is print out the vale, else do nothing. Them move onto the next value.
Look at what the functions do on the left here
[uk.php.net...]