<?php
include('../includes/header4.php');
$step = isset($_GET['step']) ? $_GET['step'] : 0;
$xp = isset($_GET['xp']) ? $_GET['xp'] : '';
$xp2 = 5017;
$label = 0;
if ($step == 0)
{
?>
<br> <br>
<form action='' method="GET">
<fieldset>
<legend>Current XP Amount:</legend>
<label for="xp">XP</label>
<input type="number" size="30" id="xp" name="xp" placeholder="(max of 5017)" value=''>
<br> <br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
</fieldset>
</form>
<?php
}
else
{
// Calculating XP Amount and Setting a Level
// $xp3 = calculate_cost($xp, $xp2);
$xp3 = $xp2 - $xp;
echo("<br>xp3 = $xp3<br>");
if ($xp <= 82)
{
echo('<h3>You Are Level 1,</h3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 83 && $xp <= 173)
{
echo('<h3>You Are Level 2,</h3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 174 && $xp <= 275)
{
echo('<h3>You are Level 3,</h3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 276 && $xp <= 387)
{
echo('<h3>You are Level 4,</h3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 388 && $xp <= 511)
{
echo('<H3>You are Level 5,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 512 && $xp <= 649)
{
echo('<H3>You are Level 6,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 650 && $xp <= 800)
{
echo('<H3>You are Level 7,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 801 && $xp <= 968)
{
echo('<H3>You are Level 8,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 969 && $xp <= 1153)
{
echo('<H3>You are Level 9,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
elseif ($xp >= 1154 && $xp <= 1357)
{
echo('<H3>You are Level 10,</H3>');
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
}
echo('<hr>');
// --------- switch -------------
$lable = 0;
switch ($xp)
{
case ($xp <= 82);
$lable = 1;
break;
case ($xp >= 83 && $xp <= 173);
$lable = 2;
break;
case ($xp >= 174 && $xp <= 275);
$lable = 3;
break;
case ($xp >= 276 && $xp <= 387);
$lable = 4;
break;
case ($xp >= 388 && $xp <= 511);
$lable = 5;
break;
case ($xp >= 512 && $xp <= 649);
$lable = 6;
break;
case ($xp >= 650 && $xp <= 800);
$lable = 7;
break;
case ($xp >= 801 && $xp <= 968);
$lable = 8;
break;
case ($xp >= 969 && $xp <= 1153);
$lable = 9;
break;
case ($xp >= 1154 && $xp <= 1357);
$lable = 10;
break;
}
echo("<h3>You Are Level $lable (using switch)</h3>");
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
echo('<hr>');
$lable = checkLevel($xp);
echo("<h3>You Are Level $lable (using function)</h3>");
echo sprintf("<h3>with %s XP to go until Level 20!", $xp3);
?>
<br> <br> <br>
<form action='' method="GET">
<fieldset>
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Go Again">
</fieldset>
</form>
<?php
}
include('../includes/footer4.php');
//========= checkLevel ========
function checkLevel($a)
{
$levels = array(83,173,275,387,511,649,800,968,1153,1357);
$level = 0;
$last = 0;
foreach($levels as $v)
{
$level++;
if($a > $last && $a <= $v)
{
break;
}
$last = $v;
}
return $level;
}
?>
Last modified: November 10 2022
Line Count: 172