Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, April 28, 2013

Array Element Tally


Say you had an election, and you needed to tally the votes for each candidate. All you need to do is enter the name of each candidate once it is read. Then, click the ADD button (or press the ENTER key) to add it to the array, as an array element. If you made a mistake, just click the REMOVE button to remove the last element added. The tally results are updated automatically. Each name will show the number of votes it received as well as the total votes cast for the entire election.

Type in the ARRAY ELEMENT:

Add

Remove

TALLY:

Saturday, April 27, 2013

Codecademy Sample Solution: Challenge Time


<!DOCTYPE html>
<html>
    <head>
 <title> Challenge Time! </title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <?php
          // Your code here
            class Cat{
                public $isAlive = true;
                public $numLegs = 4;
                public $name;
               
                public function __construct($name){
                    $this->name = $name;
                }
               
                public function meow(){
                    return "Meow meow";
                }
            }
           
            $cat1 = new Cat('CodeCat');
            echo $cat1->meow();
        ?>
      </p>
    </body>
</html>

Codecademy Sample Solution: Putting It All Together, Part II


<!DOCTYPE html>
<html>
<head>
 <title> Practice makes perfect! </title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <!-- Your code here -->
        <?php
            class Dog{
                public $numLegs = 4;
                public $name;
               
                public function __construct($name){
                    $this->name = $name;
                }
               
                public function bark(){
                    return "Woof!";
                }
               
                public function greet(){
                    return "My name is $this->name.";
                }
            }
           
            $dog1 = new Dog('Barker');
            $dog2 = new Dog('Amigo');
            echo $dog1->bark();
            echo $dog2->greet();
        ?>
      </p>
    </body>
</html>

Codecademy Sample Solution: Putting It All Together, Part I


<!DOCTYPE html>
<html>
<head>
 <title> Practice makes perfect! </title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <!-- Your code here -->
        <?php
            class Dog{
                public $numLegs = 4;
                public $name;
               
                public function __construct($name){
                    $this->name = $name;
                }
               
                public function bark(){
                   
                }
               
                public function greet(){
                   
                }
            }
        ?>
      </p>
    </body>
</html>

Codecademy Sample Solution: A Method to the Madness


<!DOCTYPE html>
<html>
<head>
 <title>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <!-- Your code here -->
        <?php
            class Person{
                public $isAlive = true;
                public $firstname;
                public $lastname;
                public $age;
               
                public function __construct($firstname, $lastname, $age){
                    $this->firstname = $firstname;
                    $this->lastname = $lastname;
                    $this->age = $age;
                }
               
                public function greet(){
                    return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
                }
            }
            $teacher = new Person('boring', '12345', 12345);
            echo $teacher->greet();
            $student = new Person('Anony', 'mous', 100);
            echo $student->greet();
        ?>
      </p>
    </body>
</html>

Codecademy Sample Solution: Property Panic (2)


<!DOCTYPE html>
<html>
<head>
 <title>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <!-- Your code here -->
        <?php
            class Person{
                public $isAlive = true;
                public $firstname;
                public $lastname;
                public $age;
               
                public function __construct($firstname, $lastname, $age){
                    $this->firstname = $firstname;
                    $this->lastname = $lastname;
                    $this->age = $age;
                }
            }
            $teacher = new Person('boring', '12345', 12345);
            $student = new Person('Anony', 'mous', 100);
            echo $student->age;
        ?>
      </p>
    </body>
</html>

Codecademy Sample Solution: Property Panic (1)


<!DOCTYPE html>
<html>
<head>
 <title>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
      <p>
        <!-- Your code here -->
        <?php
            class Person{
                public $isAlive = true;
                public $firstname;
                public $lastname;
                public $age;
            }
            $teacher = new Person();
            echo "$teacher->isAlive";
            $student = new Person();
        ?>
      </p>
    </body>
</html>

This is an example of scrolling text using Javascript.

Popular Posts