0

I have just signed up for Treehouse training and I have this mini challenge to complete. I can't get this to work. If the variable is set to 'vanilla' I will get a successful output. However, if I use 'cookie dough' then I get a syntax error, I think it may be because of the space between cookie and dough in the varial prehaps?

 <?php 
        $flavor = cookie dough;
        echo "<p> Your favourite flavor is ";
        echo $flavor;
        echo ".</P>";
        if ($flavor == "cookie dough") {
            echo "<p> Yeah I like cookie dough aswell! </p>";
        }
    ?>
ProEvilz
  • 5,094
  • 8
  • 41
  • 72
  • 1
    Maybe you want tp check in php.net how to assign strings to variable. You need to quote them. – Royal Bg Aug 20 '13 at 10:28
  • 2
    You need to learn how to [READ and debug](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) error messages. Everything you needed to solve the problem was in the error message. on the line given in the error message you have a string that php did not expect – Anigel Aug 20 '13 at 10:29

5 Answers5

2

Here you forgot ""

$flavor = cookie dough;

should be

$flavor = "cookie dough";
          ^            ^
Yogesh Suthar
  • 30,136
  • 18
  • 69
  • 98
2

Enclose $flavor variable value with quotes.

<?php 
        $flavor = "cookie dough";
        echo "<p> Your favourite flavor is ";
        echo $flavor;
        echo ".</P>";
        if ($flavor == "cookie dough") {
            echo "<p> Yeah I like cookie dough aswell! </p>";
        }
    ?>
Shankar Narayana Damodaran
  • 66,874
  • 43
  • 94
  • 124
1

Simply,

$flavor = cookie dough;

isn't a correct code, enclose with quotes. You can see possible ways to define strings here.

Alma Do
  • 36,374
  • 9
  • 70
  • 101
1
$flavor = cookie dough;

should be

$flavor = 'cookie dough'; or

$flavor = "cookie dough";

To define a string you should be use "'" or '"';

som
  • 4,614
  • 2
  • 19
  • 36
1

You forgot to enclose cookie dough in quotes:

$flavor = "cookie dough";
Paddyd
  • 1,850
  • 15
  • 25