Jump to content

Not Printing Correct Greating


garyblackpool
 Share

Recommended Posts

Hi i having problem with this code its not bringing the correct greating. it is just showing the "new roll" greating after a turn has been taken. I have checked and it seems to be right thanks x

<?printGreeting();printDice();printForm();function printGreeting(){	global $guess, $numPetals;	if (empty($guess)){		print"<h3>Welcome to Petals Around the Rose</h3>";	} else if ($guess == $numPetals){		print"<h3> You Got it</h3>";	}else{		print <<<HERE		<h3>From your last try </h3>		you guessed: $guess</br>		-and the correct answer was: $numberPetals around the rose</br> HERE;}//end if	}//end greating	function printDice(){	global $numPetals;		print "<h3>New Roll:</h3>";	$numPetals = 0;		$die1 = rand(1,6);	$die2 = rand(1,6);	$die3 = rand(1,6);	$die4 = rand(1,6);	$die5 = rand(1,6);	$die6 = rand(1,6);		showDie($die1);	showDie($die2);	showDie($die3);	showDie($die4);	showDie($die5);	showDie($die6);		print "<br>";	calcNumPetals($die1);	calcNumPetals($die2);	calcNumPetals($die3);	calcNumPetals($die4);	calcNumPetals($die5);	calcNumPetals($die6);	} //end dice	function showDie($value){	print <<<HERE	<img src="dice$value.jpeg"	height=100	width=100HERE;} // end show Diefunction calcNumPetals($value){		global $numPetals;	switch ($value) {		case 3:			$numPetals +=2;			break;		case 5:			$numPetals += 4;			break;} //end switch} //end switchfunction printForm(){	global $numPetals;		print<<<HERE	<h3> How many petals around the rose?</h3>		<form method = "post">	<input type = "text"			name = "guess"			value= "0">	<input type ="hidden"		name="numPetals"		value="$numPetals">	</br>	<input type ="submit">	</form>	</br>	<a href = "petalHelp.html"	target ="helpPage">	give me a hint!</a>HERE;} //end print form?>

Link to comment
Share on other sites

What does <<<Here ... HERE;mean?

Link to comment
Share on other sites

Ah, I see. What's the advantage?

Link to comment
Share on other sites

Well, why not just echo since you're not using printf?

Link to comment
Share on other sites

I routinely echo multi line blocks, I just use single quotes to start and end and since I have a habit of using double quotes everywhere else, I never need to escape anything *shrugs*

Link to comment
Share on other sites

Heredoc syntax is for outputting large blocks of text where you want to do variable replacement. Single quotes do not do variable replacement. The nowdoc syntax is similar to a heredoc except it does not replace variables.heredoc : double-quote :: nowdoc : single-quoteMaybe you haven't found a need for heredocs or nowdocs at this point, but eventually you will.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...