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,310
  • 9
  • 44
  • 74
  • 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,424
  • 18
  • 72
  • 100
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
  • 68,075
  • 43
  • 96
  • 126
1

Simply,

$flavor = cookie dough;

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

Alma Do
  • 37,009
  • 9
  • 76
  • 105
1
$flavor = cookie dough;

should be

$flavor = 'cookie dough'; or

$flavor = "cookie dough";

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

som
  • 4,650
  • 2
  • 21
  • 36
1

You forgot to enclose cookie dough in quotes:

$flavor = "cookie dough";
Paddyd
  • 1,870
  • 16
  • 26