EvilZone
Programming and Scripting => Web Oriented Coding => : Rytiou October 20, 2013, 03:11:49 PM
-
So I've been learning php for a little bit and I decided I wanted to make a simple program to test what I learnt. I know this is nothing exciting really but I wanted to make something simple from scratch without a book telling me what to do. If you can tell me how I did on this 99 bottles of beer program I'd really appreciate it :).
<?php
// Sets the initial amount of beer
$count = 99;
// Prints the lyrics while count is greater than or equal to 1
while ($count >= 1)
{
echo $count.' bottles of beer on the wall, '.$count.' bottles of beer. <br>';
echo 'Take one down and pass it around, '.($count - 1).' bottles of beer on the wall';
echo '<br>';
// Decreases count by one
$count --;
}
?>
-
Not bad, could use pre-decrement though:
echo 'Take one down and pass it around, ' . --$count . ' bottles of beer on the wall';
echo '<br>';
-
Well I tried doing that but what ended up happening was the number was decreasing by two rather than one. And when I remove the bottom one but keep the one you put in it does this:
http://gyazo.com/954cc33babf58434114597c2cd910905
-
Isen't the point of the 99-bottles-of-beer song in code to make it as small as possible? Here is what I got on short notice:
[gist]anonymous/7071149[/gist]
-
Isen't the point of the 99-bottles-of-beer song in code to make it as small as possible? Here is what I got on short notice:
[gist]anonymous/7071149[/gist]
Well this was the shortest possible way that I could think of with my current knowledge. Also, if you're trying to show me an example it's either not there or it's just my browser.
-
Well this was the shortest possible way that I could think of with my current knowledge. Also, if you're trying to show me an example it's either not there or it's just my browser.
You need to enable javascript. Jesus, what is it with people and having javascript disabled..
EDIT: Direct link: https://gist.github.com/anonymous/7071149#file-gistfile1-php
-
You need to enable javascript. Jesus, what is it with people and having javascript disabled..
Pretty good security practice, if you ask me.
-
You need to enable javascript. Jesus, what is it with people and having javascript disabled..
EDIT: Direct link: https://gist.github.com/anonymous/7071149#file-gistfile1-php
Aah didn't even think about that. Guess I still have a bunch to learn. Thanks for showing me man :).
-
Pretty good security practice, if you ask me.
Globally disabling javascript does more harm than good if you ask me. If you need to disable javascript to be secure while browsing, you should consider adapting a new browsing habit.
-
Globally disabling javascript does more harm than good if you ask me. If you need to disable javascript to be secure while browsing, you should consider adapting a new browsing habit.
Well the only reason I had disabled was because I was testing a firefox addon and I forgot that I had it on still.
-
The very last verse will be grammatically wrong, won't it?
-
The very last verse will be grammatically wrong, won't it?
Indeed, needs to say bottle not bottles. Should be simple enough.
-
for ($i = 100; $i > 0; $i--) {
echo sprintf('%1$d %3$s of beer on the wall, %1$d %3$s of beer.<br>Take one down and pass it around, %2$d %4$s of beer on the wall<br>', $i, ($i-1), ($i==1) ? 'bottle' : 'bottles', (($i-1)==1) ? 'bottle' : 'bottles');
}
This will, to my knowledge, fix the grammar in the last verse