<?php

/**
 * @preserve 87c0bbfb687cd064936f4a029e5e8650
 *
 * 87c0bbfb687cd064936f4a029e5e8650
 * htmlphp
 * lab2
 * v2
 * rasb14
 * 2017-09-08 17:32:44
 * v2.3.3 (2017-06-12)
 *
 * Generated 2017-09-08 19:32:45 by dbwebb lab-utility v2.3.3 (2017-06-12).
 * https://github.com/mosbth/lab
 */

// Set error reporting to verbose
error_reporting(-1);              // Report all type of errors
ini_set('display_errors', 1);     // Display all errors

// Load and create object with lab utilities
require __DIR__ . "/.Dbwebb.php";
$dbwebb = new Dbwebb();



/** ===================================================================
 * Lab 2 - htmlphp
 *
 * If you need to peek at examples or just want to know more, take a look at
 * the [PHP manual](http://php.net/manual/en/langref.php).
 *
 * Here you will find everything this lab will go through and much more.
 *
 */



/** -------------------------------------------------------------------
 * Section 1 . Strings and basic string operations
 *
 * The foundation for strings.
 *
 */



/**
 * Exercise 1.1 (1 points)
 *
 * Create a variable called `wordOne` and assign the word `"earth"` to it.
 *
 * Create another variable called `wordTwo` and assign the word `"kitten"` to
 * it.
 *
 * Concatenate the two strings, and separate them by a hyphen `-`, into a new
 * variable called `result`.
 *
 * Answer with the result-variable.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$wordOne = "earth";
$wordTwo = "kitten";

$ANSWER = $wordOne . "-" . $wordTwo;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.1", $ANSWER, false);

/**
 * Exercise 1.2 (1 points)
 *
 * Create a variable, `floatNumber`, and assign the value 56.86. Concatenate
 * your variable `wordOne` with your variable `floatNumber`, separate the
 * words with a `=`. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$floatNumber = 56.86;

$ANSWER = $wordOne . "=" . $floatNumber;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.2", $ANSWER, false);

/**
 * Exercise 1.3 (1 points)
 *
 * Create a variable, `intNumber`, and assign the value 182. Concatenate your
 * variable `intNumber` with your variable `wordTwo`, separate the words with
 * a space. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$intNumber = 182;

$ANSWER = $intNumber . " " . $wordTwo;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.3", $ANSWER, false);

/**
 * Exercise 1.4 (1 points)
 *
 * Create the string: `"There are 182 kitten's doing some earth."` by
 * combining pure text with the values of your variables `wordOne`, `wordTwo`
 * and `intNumber`. Store the resulting text in a variable `sentence`. Answer
 * with the variable.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$sentence = "There are " . $intNumber . " " . $wordTwo . "'s doing some " . $wordOne . ".";

$ANSWER = $sentence;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.4", $ANSWER, false);

/**
 * Exercise 1.5 (1 points)
 *
 * Use `strlen()` to find the length of the variable `sentence`. Answer with
 * the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = strlen($sentence);

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.5", $ANSWER, false);

/**
 * Exercise 1.6 (1 points)
 *
 * Use `substr()` to find the character at index 3 in the word `"foot"`.
 * Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = substr("foot", 3, 1);

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.6", $ANSWER, false);

/**
 * Exercise 1.7 (1 points)
 *
 * Use `substr()` to find the two characters at index 3 and 4 in the word
 * `"crocodile"`. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = substr("crocodile", 3, 2);

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.7", $ANSWER, false);

/**
 * Exercise 1.8 (1 points)
 *
 * Use `strpos()` to find the first matching index of the character `o` in the
 * word `"monkey"`. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = strpos("monkey", "o");

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.8", $ANSWER, false);

/**
 * Exercise 1.9 (1 points)
 *
 * Use `strpos()` to find the first matching, (if any), index of the
 * characters `xyz` in the word `"monkey"`. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = strpos("monkey", "xyz");

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("1.9", $ANSWER, false);

/** -------------------------------------------------------------------
 * Section 2 . Conditions, booleans, if, else and else if
 *
 *
 *
 */



/**
 * Exercise 2.1 (1 points)
 *
 * Store the boolean result of the test: `273 is less than 19` in a variable.
 * Answer with the variable.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$equals = 273 < 19;

$ANSWER = $equals;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("2.1", $ANSWER, false);

/**
 * Exercise 2.2 (1 points)
 *
 * Answer with the boolean value of: `204 is larger than 321`.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$ANSWER = 204 > 321;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("2.2", $ANSWER, false);

/**
 * Exercise 2.3 (1 points)
 *
 * Sum up the numbers: 8, 10, 2, 9 and 2. Save the result in a variable called
 * `totalSum`.
 *
 * Create an if/elseif-statement to see if `totalSum` is higher, lower or
 * equal to 31.
 *
 * Answer with the corresponding result as a string: `"higher"`, `"lower"`,
 * `"equal"`.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$answer = "equal";
$totalSum = 8 + 10 + 2 + 9 + 2;
if ($totalSum > 31) {
    $answer = "higher";
} elseif ($totalSum < 31) {
    $answer = "lower";
}

$ANSWER = $answer;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("2.3", $ANSWER, false);

/**
 * Exercise 2.4 (1 points)
 *
 * Create an if-statement that checks if a value is between (or equal to) 22
 * and  38. Use the variable `totalSum` from last exercise to test the
 * if-statement. Answer with a boolean `true` if the value is between the
 * values, otherwise respond with `false`.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$result = false;
if ($totalSum >= 22 && $totalSum <= 38) {
    $result = true;
}

$ANSWER = $result;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("2.4", $ANSWER, false);

/** -------------------------------------------------------------------
 * Section 3 . Iteration and loops
 *
 * For-loops and while-loops.
 *
 */



/**
 * Exercise 3.1 (1 points)
 *
 * Create a while-loop that adds 4 to the number 64, 80 times. Use variables
 * to store the numbers. Answer with the result.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$number = 64;
while ($number < 4 * 80 + 64) {
    $number += 4;
}

$ANSWER = $number;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("3.1", $ANSWER, false);

/**
 * Exercise 3.2 (1 points)
 *
 * Create a while-loop that subtracts 6.25 from the number 689 until the
 * number is between (not equal to) 29 and 39. Answer with the final result as
 * a float, rounded to 2 decimals.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$number = 689;
while ($number >= 39) {
    $number -= 6.25;
}

$ANSWER = round($number, 2);

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("3.2", $ANSWER, false);

/**
 * Exercise 3.3 (1 points)
 *
 * Create a for-loop that iterates from 0 to (including) 18. Add the integer
 * value for each iteration to a string and separate each item with a `,`
 * (comma). Answer with the final string without an ending `,`.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$text = "";
for ($i = 0; $i <= 18; $i++) {
    if ($i < 18) {
        $text .= $i . ",";
    } else {
        $text .= $i;
    }
}

$ANSWER = $text;

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("3.3", $ANSWER, false);

/** -------------------------------------------------------------------
 * Section 4 . Extra assignments
 *
 * These questions are worth 3 points each. Solve them for extra points.
 *
 */



/**
 * Exercise 4.1 (3 points)
 *
 * Create a for-loop that goes through (and including) the numbers 29 to 39.
 * If the current number is even, you should multiply it with PI and add it to
 * a variable `res`. If the current number is odd, you should subtract the
 * square root of it, from the variable `res`. If the current number ends with
 * a zero, then ignore it. Answer with the final result of `res` and round it
 * to the nearest higher integer value.
 *
 * Write your code below and put the answer into the variable ANSWER.
 */

$res = 0;
for ($i = 29; $i <= 39; $i++) {
    if ($i % 10 != 0) {
        if ($i % 2 == 0) {
            $res += $i * pi();
        } else {
            $res -= sqrt($i);
        }
    }
}

$ANSWER = (int)round($res);

// I will now test your answer - change false to true to get a hint.
echo $dbwebb->assertEqual("4.1", $ANSWER, false);


// Wrap it up
exit($dbwebb->exitWithSummary());
