Designing Solutions Through Programming block 1 Lesson Notes - October 12 2017: Difference between revisions
Mr. MacKenty (talk | contribs) (Created page with " __NOTOC__ <table cellspacing="10" style="width:100%;"> <tr> <td style="margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1em; backgr...") |
Mr. MacKenty (talk | contribs) |
||
Line 28: | Line 28: | ||
By the end of class you should say: | By the end of class you should say: | ||
* I can | * I can define array | ||
* | |||
<syntaxhighlight lang="php"> | |||
<?php | |||
// this is where we define an array: | |||
$classes=["fighter","cleric","magic user","barbarian","monk"]; | |||
echo "<hr>"; | |||
// this is how we "dump" an array to see it (blech, ugly) | |||
var_dump($classes); | |||
echo "<hr>"; | |||
// this is how we access one element in an array | |||
echo $classes[2]; | |||
echo "<hr>"; | |||
// this is how we count elements in an array | |||
echo count($classes); | |||
echo "<hr>"; | |||
// this is how we ADD something to an array | |||
$classes[] = "Archer"; | |||
var_dump($classes); | |||
echo "<hr>"; | |||
// this is how we delete an item from an array | |||
unset($classes[1]); | |||
var_dump($classes); | |||
echo "<hr>"; | |||
// loop through an array. We ITERATE through an array | |||
foreach ($classes as $i) { | |||
echo "I like $i <br>"; | |||
# echo "Please type a name for a $i : <input type=\"text\">"; | |||
} | |||
echo "<hr>"; | |||
// let's see if there is a specific element in our array: | |||
$searchTerm = "monk"; | |||
if(in_array($searchTerm,$classes)){ | |||
echo "there is a monk in the array"; | |||
} else { | |||
echo "there is not a monk in the array"; | |||
} | |||
echo "<hr>"; | |||
// let's find the index of something we want to search for: | |||
echo array_search($searchTerm,$classes); | |||
echo "<hr>"; | |||
// let's randomly select only one INDEX from our array | |||
$randomlySelectedClass = array_rand($classes,1); | |||
echo $randomlySelectedClass; | |||
// let's echo the class we just chose from our array of classes: | |||
echo $classes[$randomlySelectedClass]; | |||
/* | |||
</syntaxhighlight> | |||
</td> | </td> |
Revision as of 19:15, 12 October 2017
Our Big Idea[edit]
The function of every web application system is to accept data, process data and output information. Effective design of interdependent components results in useful function.
|
|
What are we going to learn today?[edit]Hello Class!
By the end of class you should say:
<?php
// this is where we define an array:
$classes=["fighter","cleric","magic user","barbarian","monk"];
echo "<hr>";
// this is how we "dump" an array to see it (blech, ugly)
var_dump($classes);
echo "<hr>";
// this is how we access one element in an array
echo $classes[2];
echo "<hr>";
// this is how we count elements in an array
echo count($classes);
echo "<hr>";
// this is how we ADD something to an array
$classes[] = "Archer";
var_dump($classes);
echo "<hr>";
// this is how we delete an item from an array
unset($classes[1]);
var_dump($classes);
echo "<hr>";
// loop through an array. We ITERATE through an array
foreach ($classes as $i) {
echo "I like $i <br>";
# echo "Please type a name for a $i : <input type=\"text\">";
}
echo "<hr>";
// let's see if there is a specific element in our array:
$searchTerm = "monk";
if(in_array($searchTerm,$classes)){
echo "there is a monk in the array";
} else {
echo "there is not a monk in the array";
}
echo "<hr>";
// let's find the index of something we want to search for:
echo array_search($searchTerm,$classes);
echo "<hr>";
// let's randomly select only one INDEX from our array
$randomlySelectedClass = array_rand($classes,1);
echo $randomlySelectedClass;
// let's echo the class we just chose from our array of classes:
echo $classes[$randomlySelectedClass];
/*
|
What is our homework?[edit]
|
How am I being assessed today?[edit]I will assess you formatively today, and make a professional judgement to what extent you understand our learning material. I will use observation, your written work, answers to questions, and contribution to class discussions as data to make my decisions. I normally record my observations in a "evidence of learning" spreadsheet, which I will happily share with you privately if you so wish. I usually need a day or two notice. |
|
As a computer scientist, you have:[edit]
|
|
Credits[edit] |