Midterm Practice Flashcards
How do we select the id attribute in css?
“#id”
How do we select the class attribute in css?
.class
What does “p” select in css?
Selects all the paragraphs
What does “p” select in css?
Selects all the paragraphs
What does “div p” select is css?
Selects all paragraphs inside div elements
What does “div, p” select in css?
Selects all the div and p tags
What does “div+p” select in css?
Selects all the sibling p tags that immediately follow a div tag
“<div></div>”
“<p></p> <– this one–>”
“<p></p> <– this does not follow a div –>”
What does :hover do in css?
Applies a style to an element when the mouse is over it
Code test:
<?php
$pass = “test”;
$hash1 = password_hash($pass, PASSWORD_BCRYPT);
$hash2 = password_hash($pass, PASSWORD_BCRYPT);
if($hash1 == $hash2){
echo “matches”;
}
else{
echo “doesn’t match”;
}
?>
doesn’t match (random salt is assigned during hash to prevent two or more users from having the same password key)
What does == do?
Value equality matches but not type
What does === do?
Value AND type equality
What does $x++ do?
Increments x by 1
What does $x– do?
Decrements x by 1
What does && do?
Logical AND (both conditions must be true)
“What does || do?”
Logical OR (either condition must be true)
What does ! typically do in !$x?
Negates it (flips the boolean or truthy value)
What does % do in $x % $y?
Remainder/Modulus/Modulo
What does . do in php?
Concats data/variables
What does + do in php?
Addition Arithmetic
In SQL how do you do a partial match on a column?
LIKE and the % wildcard
So LIKE “hi%” partial matches what?
Any data in the column starting with hi
So LIKE “%hi%” partial matches what?
Any data in the column that contains hi
So LIKE “%hi” partial matches what?
Any data in the column ending in hi
In SQL how do you select unique data?
SELECT DISTINCT
In JS what does console.log() do?
Prints to the developer console
In JS what does confirm() do?
Built in dialog providing a positive and negative action
In JS what does prompt() do?
Built in dialog asking for user input
while:
keeps running as long as the condition is true
do while:
runs at least once and continues as long as true
foreach:
loops over each item in a collection
for:
loops a specific number of times
Find Elements
let ele = document.getElementById("hi");
console.log(ele); // what's the value
<body>
<div>Hello</div>
</body>
Null; runs before page is ready
Form Submit
<!-- the url contains ?name=Joe&age=50 -->
<form>
<input></input>
<input></input>
</form>
<?php //assuming the form was just submitted
var_dump($_REQUEST);
//what is the output of $_REQUEST?
?>
[ “job”:”Painter”, “age”:51, “name”: “Joe” ]
Logic Check 1
<?php
$x = 0;
for($i = 0; $i < 3000; $i++){
$x++;
if($x % 2 == 0){
$x–;
}
}
echo “x is $x”;
?>
x is 1
Logic Check 2
<?php
$x = 0;
for($i = 0; $i < 3000; $i++){
$x++;
if($i % 2 == 0){
$x–;
}
}
echo “x is $x”;
?>
x is 1500
Logic Check 3
<?php
$x = 0;
for($i = 0; $i < 3000; $i++){
$x++;
if($x > 2){
$x–;
}
}
echo “x is $x”;
?>
x is 2
Logic Check 4
<?php
$x = 0;
for($i = 0; $i < 3000; $i++){
if($x % 2 == 0){ $x--; } if($i % 2 == 0){ continue; } $x++; } echo "x is $x"; ?>
x is 0
Defined Variables
<?php
while($x++ < 10){
echo “$x <br></br>”;
}
//does x need to be defined?
?>
no, it’s a warning for now. PHP will do it’s best to assume the initial value. Since it’s addition it can assume you want it to be an int so it uses the default value of 0 then applies the arithmetic.
Random onload sample
window.addEventListener("load", () => {
let eles = document.getElementsByTagName("div");
console.log(eles);
for (let i = 0; i < eles.length; i++) {
let t = eles[i].innerText;
let otherIndex = parseInt(Math.random() * eles.length);
eles[i].innerText = eles[otherIndex].innerText;
eles[otherIndex].innerText = t;
}
});
<body>
<div>Hello</div>
<div>Bye</div>
<div>What?</div>
<div>Who?</div>
<div>Where?</div>
</body>
Update an immediate sibling
<input></input>
<span>This will change</span>