What I do not do right (or what i'm missing)


#1

<?php
//Add while loop below
$an= 2015;
while($an < 2024) {

$an ++;

    if($an= $an + 4){            
        echo "<div class=\"coin\">bis</div>";
        } else{
           echo "<div class=\"coin\">nim</div>";
            };

    };
?>

I want the while loop to show me leap years($an= $an + 4) in

bis
, and all others in
nim

#2

Is this an exercise? i can't find it. What exactly are you trying to achieve?

First of all, i am a bit worried about this:

if($an= $an + 4)

you have a if statement (condition) but rather then checking for a condition (two equal signs) you asign $an a value of $an + 4.

even if you had:

if($an==  $an + 4)

this statement will never be true, $an does never equal $an + 4

shouldn't your if statement be something like:

if ($an % 4 == 0}

if $an module 4 equals zero, it is a leapyear


#3

it is the exercise 3 from LOOPS: WHILE AND DO-WHILE. As a result I want the while loop to show me everi four years with bis the others with nim


#4

<?php

    //this looks good 
    $an= 2015;   
         while($an < 2024) {
            $an ++;
            // here we have some mistakes 
            if($an%4 == 0){            
                  echo "<div class=\"coin\">bis</div>";
            } else {
                    echo "<div class=\"coin\">nim</div>";
            };
         };

?>


#5

if you followed the steps i provided in my answer, you would have gotten exactly that output. Why am i writing answers if they are not being read?


#6

OK. It works. Thank you very much


#7

It works thank you once again. )))))))


#8

Thak you. this is what I need.


#9

You can indeed take over dookoo_de answer, it will work, but i wanted you to do most of the thinking, which i hoped teached you a lot. Oh, something i wanted to say, when you add a html element with id/class or any other attribute, it is fine to you use apostrophe (') rather then quotation mark ("), which saves you the trouble of escaping the quotation marks:

echo "<div class='coin'>bis</div>";

#11

Gleb078, Do you speak Romanian? "An" in Romanian translates to "years." :relaxed:


#12

da desigur:) vorbesc romana