Within your \"practice\" folder, create a program called \"practice_program1.php
ID: 3739320 • Letter: W
Question
Within your "practice" folder, create a program called "practice_program1.php"
In this program, you will create a custom size table filled with random letters, from A to Z.
The user should be able to select five table sizes: 6x6, 7x7, 8x8, 9x9 and 10x10.
The user should be able to select a letter to find, from A to Z, using a dropdown menu.
Tip: A = chr(65) and Z=chr(90)
The user should also be able to select a letter to omit, from A to Z, using a dropdown menu.
The "letter to find" must be shown only once within the table.
The "letter to omit" must NOT be shown within the table.
An error message must be displayed if the "letter to find" and "letter to omit" are the same
Letters A to G should be red, H to O should be blue, and the remaining should be green.
an example of the program is hosted herehttp://hosting.otterlabs.org/laramiguel/cst336/midterm/practice/find_the_letter.php
rubric here
1 The page includes the basic form elements as in the Program Sample: Dropdown menus, radio buttons, submit button 5 2 When submitting the form, a "Find the Letter x" header is displayed, where "x" is the letter selected by the user 5 3 When submitting the form, a "Letter to Omit: x" message is displayed, where "x" is the letter to omit, selected by the user 5 4 When submitting the form, a table is created and filled with random letters 5 5 The size of the table corresponds to the one selected by the user 5 6 The letter selected by the user is shown only once 10 7 The letter to omit is not shown in the table 10 8 An error message must be displayed if the "letter to find" and "letter to omit" are the same 5 9 The letters are shown in the right colors: red, blue, and green 5 12 At least five CSS rules are includedExplanation / Answer
If you need any help, give me comment...
<?php
// $arr = [['name'=>'Bufferfree', 'id'=>12, 'weight'=>70.5, 'abilities'=>"Compound Eyes", "img"=>"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/012.png"],
// ['name'=>'Reticate', 'id'=>20, 'weight'=>40.8, 'abilities'=>"Run Away, Guts", "img"=>"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/020.png"],
// ['name'=>'Nidorina', 'id'=>30, 'weight'=>44.1, 'abilities'=>"Poision Point, Rivalry", "img"=>"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/030.png"]
// ];
// echo "<table border='1px'><tr>";
// for($i=0; $i<count($arr); $i++){
// echo "<td>name: ".$arr[$i]['name']."<br />id: ".$arr[$i]['id']."<br />weight: ".$arr[$i]['weight']."<br />abilites: ".$arr[$i]['abilities']."<br /><img src="".$arr[$i]["img']."' /></td>";
// }
// echo "</tr></table>";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Find the Letter</title>
<meta name="author" content="CHEGG USER">
<style>
td {
font-size: 1.8em;
}
#wrapper {
margin: 0 auto;
width: 800px;
text-align: center;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="directions">
<h3> Find the Letter!</h3>
<strong> Select a Letter to Find:</strong>
<form method='get'>
<select name="letterToFind">
<option value='A'>A</option><option value='B'>B</option><option value='C'>C</option><option value='D'>D</option><option value='E'>E</option><option value='F'>F</option><option value='G'>G</option><option value='H'>H</option><option value='I'>I</option><option value='J'>J</option><option value='K'>K</option><option value='L'>L</option><option value='M'>M</option><option value='N'>N</option><option value='O'>O</option><option value='P'>P</option><option value='Q'>Q</option><option value='R'>R</option><option value='S'>S</option><option value='T'>T</option><option value='U'>U</option><option value='V'>V</option><option value='W'>W</option><option value='X'>X</option><option value='Y'>Y</option><option value='Z'>Z</option> </select>
<br /><br />
Select Table Size:
<select name="tableSize">
<option value="6">6x6</option>
<option value="7">7x7</option>
<option value="8">8x8</option>
<option value="9">9x9</option>
<option value="10">10x10</option>
</select>
<br /><br />
Select Letter to Omit:
<select name="letterToOmit">
<option value='A'>A</option><option value='B'>B</option><option value='C'>C</option><option value='D'>D</option><option value='E'>E</option><option value='F'>F</option><option value='G'>G</option><option value='H'>H</option><option value='I'>I</option><option value='J'>J</option><option value='K'>K</option><option value='L'>L</option><option value='M'>M</option><option value='N'>N</option><option value='O'>O</option><option value='P'>P</option><option value='Q'>Q</option><option value='R'>R</option><option value='S'>S</option><option value='T'>T</option><option value='U'>U</option><option value='V'>V</option><option value='W'>W</option><option value='X'>X</option><option value='Y'>Y</option><option value='Z'>Z</option> </select>
<input type="submit" value="Create Table" name="submit" />
</form>
<?php
session_start();
if(isset($_GET['clearHistoryForm'])){
$_SESSION['history'] = [];
}
if(isset($_GET['tableSize']) && isset($_GET['letterToOmit']) && isset($_GET['letterToFind']) && isset($_GET['submit'])){
$tableSize = $_GET['tableSize'];
$letOmit = $_GET['letterToOmit'];
$letFind = $_GET['letterToFind'];
$_SESSION['history'][] = $letFind;
if($letOmit == $letFind){
echo "<br /><strong>Error: Letter to Find MUST Be different from Letter to Omit! </strong><br />";
}
else{
$table = [];
$exists = false;
for($i=0; $i<$tableSize*$tableSize;){
$ch = chr((rand(0,25)+65));
if($ch==$letOmit)
continue;
else if($ch==$letFind){
if(!$exists){
$table[] = $ch;
$i++;
$exists = true;
}
}
else{
$table[] = $ch;
$i++;
}
}
echo "<hr><h1> Find the letter ".$letFind."</h1><strong> Letter to Omit: ".$letOmit."</strong><br /><table border='1' cellpadding=".$tableSize."><tr>";
for($i=0; $i<$tableSize*$tableSize; $i++){
if(ord($table[$i])>=ord('A') && ord($table[$i])<=ord('G'))
echo "<td>".$table[$i]."</td>";
else if(ord($table[$i])>=ord('H') && ord($table[$i])<=ord('O'))
echo "<td>".$table[$i]."</td>";
else
echo "<td>".$table[$i]."</td>";
if($i%$tableSize==$tableSize-1){
echo "</tr></tr>";
}
}
echo "</tr></table>";
}
}
?>
<br /><br />
<hr />
Letters to Find History: <?=isset($_SESSION['history'])?implode(",", $_SESSION['history']):"";?>
<form>
<input type="submit" value="Clear History" name="clearHistoryForm" />
</form>
</div>
</div>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.