Register|Login

Have a question? Click here to ask the community.

Quiz 12 – If Else Statements

| In: PHP Quizzes | 16,268 views

*You are currently not logged in and your quiz score will not be recorded. Please login or register if you would like to submit your quiz score.

Directions: Answer all questions. Any questions skipped will be scored as wrong answers. Good Luck! :)

1. What will be displayed in a browser when the following PHP code is executed:

<?php
   if (8 <= 7) {
       echo "Hello World";
   }
   else {
       echo "Hello YouTube";
   }
?>

Hello World
Hello YouTube
Hello World Hello YouTube
Nothing Will Be Displayed

2. The PHP If Else Statement can execute the code within the if and else segments at the same time?

True
False

3. What will be displayed in a browser when the following PHP code is executed:

<?php
   if (8 >= 7) {
       echo "Hello World";
   }
   else {
       echo "Hello YouTube";
   }
?>

Hello World
Hello YouTube
Hello World Hello YouTube
Nothing Will Be Displayed

4. What will be displayed in a browser when the following PHP code is executed:

<?php
   $bookColor = "red";
   $bookName = "The PHP Basics";

   if ($bookColor == "red" && $bookName == "Steve Jobs") {
       echo "You have the wrong book";
   }
   else {
       echo "You might have the right book";
   }
?>

You have the wrong book
You might have the right book
Nothing Will Be Displayed

5. What will be displayed in a browser when the following PHP code is executed:

<?php
   $x = 6;
   $y = 4;
   $sum = $x + $y; //sum = 10
   $ten = "Ten";

   if ($sum >= 10 && $ten == "Ten") {
       $answer = "Correct";
       echo "Your answer is: $answer";
   }
   else {
       $answer = "Incorrect";
       echo "Your answer is: $answer";
   }
?>

Your answer is: Incorrect
Your answer is: $answer
Your answer is: Correct
Nothing Will Be Displayed

Comment Form

You must be logged in to post a comment.

Users Online

Users Online: 2 Users

Most Users Ever Online: 91

Quiz Scores

Advertisments