Jump to content

Just don't understand!


kakes

Recommended Posts

I need to create a php page that displays a random mulitplication flashcard with answer. The background needs to be black and the font white. There needs to be an answer area with a font color of black. The page has to include instruction to the user on how to check their answer - highlight the area to the right of the equals sign. I'm supposed to useĀ  $value=rand(1,12). The two numbers that are to be multiplied are 8x12, the answer of course is 96. I've read all I can find on this and still don't understand what to do. Please help!

Link to comment
Share on other sites

Sure. Thanks for replying. This is what I have so far. You'll see that I am completely lost.

Ā 

// Variables

Ā  $title="Assignment 1" // variable to display title

Ā 

Ā  echo "<html>

Ā  Ā  Ā  <head>

Ā  Ā  Ā  Ā  <title>

Ā  Ā  Ā  Ā  $title

Ā  Ā  Ā  Ā  </title>

Ā  Ā  Ā  </head>

Ā  <body style=\"background-color:black\">Ā  Ā  Ā 

Ā 

Ā  </body>Ā 

Ā  </html>";

Ā  Ā  Ā  ?>

Ā  Ā  Ā 

Link to comment
Share on other sites

I think what you need is a basic tutorial for php.Ā  The first person you should be asking is your teacher or tutor.Ā  If you can't ask them for some reason, you can look for "php tutorial" in google and you will find several tutorials.Ā  You might need to look at a few before you find one that matches your learning style.

Ā 

I can't really help you here until you've gotten the basics.

Link to comment
Share on other sites

Okay, I've been working on this and seem to be getting how it works, somewhat. I just can't seem to figure out how I'm going to get the background black, the text white, and the multiplication answer to display in black text and only be visable when you highlight it. Any suggestions?

Ā 

Ā  echo "<html>

Ā  Ā  Ā  <head>

Ā  Ā  Ā  Ā  <title>

Ā  Ā  Ā  Ā  $title

Ā  Ā  Ā  Ā  </title>

Ā  Ā  Ā  </head>

Ā  <body>\n";

Ā 

Ā  echo "<h3>Instructions: To check your answer, highlight the area to the right of the equals mark.</h3>\n";

Ā  echo "<h1>8x12="."$multiplication</h1>\n";

Ā  Ā  Ā 

Ā  echo "</body>\n</html>"

Ā  Ā  Ā  ?>

Link to comment
Share on other sites

Well that may obscure it when the browser renders it, but it will still be clearly visible in a View --> Source, which would defeat the purpose, wouldn't it? This really should get a topic of its own, BTW.

Ā 

Simple variables can be place directly into a double-quoted string; no concatenation necessary . . .

echo "<h1>8x12=$multiplication</h1>\n";

Ā 

Link to comment
Share on other sites

I've tried putting the html code in the body tag to change the font and background color, but it doesn't work. I guess I'm missing something...maybe a semi colon or something.

Ā 

Thanks for any suggestions.

Ā 

Ā  echo "<html>

Ā  Ā  Ā  <head>

Ā  Ā  Ā  Ā  <title>

Ā  Ā  Ā  Ā  $title

Ā  Ā  Ā  Ā  </title>

Ā  Ā  Ā  </head>

Ā  <body style=\"background-color:black\font color:white">\n";

Ā 

Ā  echo "<h3>Instructions: To check your answer, highlight the area to the right of the equals mark.</h3>\n";

Ā  echo "<h1>8x12="."$multiplication</h1>\n";

Ā  Ā  Ā 

Ā  echo "</body>\n</html>"

Ā  Ā  Ā  ?>

Ā  Ā  Ā 

Link to comment
Share on other sites

Thanks! So appreciated! Now, how do I get the answer to display in black and only be visable when you highlight it? I think I would need to somehow write it into the variable but maybe it needs to be in the code line...not sure. I'll work on it but will appreciate any suggestions.

Link to comment
Share on other sites

I've got a new problem. I have to use rand() to generate the random multiplication. I've been trying everything, watching tutorials, reading my text, another reference book that I bought, still don't have what I need. This code is a mess but it's all I could come up with. You'll see how crazy I've become! Thanks.

Ā 

/Variables

Ā  $title = Assignment1; // variable to display title

Ā  $value1 = rand(1,12); // first number as a variable

Ā  $value2 = rand(1,12); // second number as a variable

Ā  $total = rand(1,12); // total of the two numbers as a variable

Ā 

Ā  echo "<html>

Ā  Ā  Ā  <head>

Ā  Ā  Ā  Ā  <title>

Ā  Ā  Ā  Ā  $title

Ā  Ā  Ā  Ā  </title>

Ā  Ā  Ā  </head>

Ā  <body style=\"background-color:black;color:white;\">\n";

Ā 

Ā  echo "<h3>Instructions: To check your answer, highlight the area to the right of the equals mark.</h3>\n";

Ā  echo "<h1>($value1*$value2)=$total</h1>\n";

Ā  Ā  Ā 

Ā  echo "</body>\n</html>"

Ā  Ā  Ā  ?>

Ā 

Help...

Link to comment
Share on other sites

You really aren't that far off.

Ā 

$total = rand(1,12); would have to accidentally generate the correct total. To get the right number, you'd need to find the product of the randomly generated multiplicand ($value1) and multiplier ($value2).

Ā 

$total = $value1 * $value2;

Ā 

Then, you just need to tweak the way you echo the values so the values are echoed with the correct total, and add the color to the answer. If you have any questions about what I changed or why, just say so.

Ā 

<?php
$title = Assignment1; // variable to display title
Ā   $value1 = rand(1,12); // first number as a variable
Ā   $value2 = rand(1,12); // second number as a variable
Ā   $total = $value1 * $value2; // total of the two numbers as a variable

Ā   echo "<html>
Ā  Ā  Ā  <head>
Ā  Ā  Ā  Ā   <title>
Ā  Ā  Ā  Ā   $title
Ā  Ā  Ā  Ā   </title>
Ā  Ā  Ā  </head>
Ā   <body style=\"background-color:black;color:white;\">\n";

Ā   echo "<h3>Instructions: To check your answer, highlight the area to the right of the equals mark.</h3>\n";
Ā  Ā  echo "<h1>$value1 * $value2Ā  = <font color=\"black\">$totalĀ </font></h1>\n";

Ā   echo "</body>\n</html>"
Ā  Ā  Ā  ?>

Ā 

EDIT: Simplified the echo a bit . . .

Link to comment
Share on other sites

You just don't know how thankful I am that you took the time to help with this. I was at my wit's end. After you explained about the variables and how I had done the echo, it was so much clearer. I wasn't thinking it through, I suppose. Glad to hear I was at least close to getting it. I just needed a little push. Thanks again!! It worked like a charm!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.