Make a website where the very top is a dark color with light colored text. The top should take up 100px and have a large title that is centered.
Make a body with a picture and then text to the right of the picture that explains what the picture is. The text should be right aligned and dark gray. The background should be white.
Many developers now get their fonts from google fonts
Click Quick Use
The link goes in your head tag
font-family: goes in your css
Change your h1 to be roboto thin and the body of your website to be roboto regular.
Margin
Padding
Border
Space outside of an object
Space inside an object
Space lining the outside of an object
Margin and Padding reading from top and then clockwise. So the code below would put 5px of space above an object, 10px of space to the right of an object, 15px below, and 20 to the left.
p{
margin: 5px 10px 15px 20px;
}
Text
You are going to make our new staff band website, take a look at the website here: http://computersciencelessons.com/band.html
http://fonts.googleapis.com/css?family=Bangers
And spend the next 20 minutes recreating it.
Pictures:
http://bit.ly/rockey-image
http://bit.ly/ap-image
http://bit.ly/ma-image
http://bit.ly/mb-image
If you want hints, hit the down arrow.
Your body tag will have 3 custom css properties, background-color, font-family, and text-align
your h1, h2, and p tags should all have 2 custom properties, font-size and color.
To make the space colored around your images, you will want to make all images have a fixed width, a background-color, and padding. (You could use border and get the same result).
To make the space colored around your images, you will want to make all images have a fixed width and padding. (You could use border and get the same result).
Since each picture is a different color, you will need to have a way to call each picture individually with css. Use an id and set the background color (or border) there.
Javascript is all about interaction. Javascript is a programming language that allows you to "teach" computers to do specific things under different conditions.
<script>
alert("Hello World!");
</script>
<script>
var num1 = 5;
var num2 = 8;
alert("num1 + num2");
alert(num1 + num2);
</script>
<script>
var num1 = 5;
var num2 = 8;
alert(num1 + num2);
alert(num1 - num2);
alert(num1 * num2);
alert(num1 / num2);
</script>
<script>
var num1 = 5;
var num2 = 8;
var num3 = 4;
var num4 = 15;
num4 % num3 //3
num4 % num2 //7
num4 % num1 //0
num3 % num4 //4
num3 % num3 //0
num3 % num2 //4
num3 % num1 //4
num2 % num1 //3
num2 % num3 //0
num2 % num4 //8
</script>
So answer the following:
3 % 2
5 % 20
20 % 5
5 % 2
7 % 3
Create 3 different alerts with the 4 variables above and no constants, one using only addition, one using only multiplication, and one using only division. Each alert should say 16.
num1 = 4
num2 = 12
num3 = 16
num4 = 1
Variables can change many times in a program, that's actually what makes them valuable.
What are some examples of variables in programs we use daily?
var x = 5;
x = x + 3;
var y = x / 2;
x = x * y;
x = (2*y + x) / y;
//what are the current values of x and y?
var name = "Ryan";
alert("Hello " + name + " how are you?");
var city = "Nashville";
var name = "Matt";
var age = 15;
Using the variables above, alert a sentence that says the city, name and age.
var start = Math.random();
Test it out a few times, what's the pattern?
The key to any good game is randomness.
Make it so it generates a random number between 1 and 100
The key to any good game is randomness.
Figure out how to round it so it is just a whole number. (google search!)
The key to any good game is randomness.
var start = Math.round(Math.random()*100);
// or
var start = Math.random()*100;
start = Math.round(start);
There are 3 major parts to any computer program
1. Sequence, the order in which things occur
2. Selection, conditional statements that are only executed when certain conditions are met.
3. Iteration, doing something many times.
var num = Math.round(Math.random()*100);
if(num > 50){
alert(num + ", that's huge!");
}
var num = Math.round(Math.random()*100);
if(num > 50){
alert(num + ", That's huge!");
}else if(num < 50){
alert(num + ", That's small!");
}
var num = Math.round(Math.random()*100);
if(num > 50){
alert(num ", That's huge!");
}else if(num < 50){
alert(num + ", That's small!");
}else{
alert("Right down the middle");
}
Generate a random integer between 0 and 50. If it's even, alert ___ is even. Otherwise alert the number.
Generate a random number between 0 and 30. If it's a multiple of 3 alert ___ is a multiple of 3. If it's a multiple of 2 alert___ is a multiple of 2.
Generate a random number between 0 and 20. If it's a multiple of 2 and 3, alert ____ is a multiple of 2 and 3.
var num = Math.round(Math.random()*10);
num = num + 10;
if(num > 20){
alert("I'm greater than 20");
}else{
alert(num / 2);
}
var answer = prompt("Guess a Number");
var answer = prompt("Guess a Number");
answer = Number(answer);
//alternative way
var answer = Number(prompt("Guess a Number");
Generate a random integer between 0 and 10. Have the user guess a number between 0 and 10. If they guess correctly, tell them they win. If the don't guess correctly, tell them how far off they were.
var car = prompt("What kind of car do you drive?");
if(car == "Honda"){
var like = prompt("Nice, do you like it?");
if(like == "yes"){
alert("Good, it would be a bummer not to like your car");
}else{
alert("I'm sorry to hear that!");
}
}
Create your own choose your own adventure game. Structure:
var answer = prompt("Do you want to go out to eat?");
if(answer == "yes"){
answer = prompt("Somewhere fancy or somewhere cheap?");
if(answer == "cheap"){
alert("Nice, we'll go on a date to KFC");
}else{
alert("Okay, sushi it is!");
}
}else{
answer = prompt("Would you rather make pizza or pasta?");
if(answer == 'pizza'){
alert("Cool, we should make pineapple pizza");
}else{
alert("Okay, but we have to make our own pasta");
}
}
Create a prompt that asks the user what day of the month their birthday is.
If the day of the month is even, alert out to them their birthday is on an even number.
If their day of the month is the same as yours, alert to them their birthday is the same as yours.
If the day of the month is in between 15 and 18, alert their birthday is in between 15 and 18
Computers are really good at doing things over and over again.
for(i = 0; i<5; i++){
alert(i);
}
What will this do?
What if I wanted to start at 2?
What if I wanted to go to 8?
What if I wanted to go up by 2 instead of 1?
Make a program that allows the user to type in the total, then type in the amount they paid. Afterwards it should say the amount of change due.
Then, it should say "You'll get ___ back in bills and ___ back in change.
Add Jquery to your website by googling google hosted jquery
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link href='http://fonts.googleapis.com/css?family=Lato:400,300,100' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Jquery is a powerful library, one of the things that makes it awesome is how it enables you to communicate with html.
var results = $('#results');
for(i = 0; i < 10; i++){
results.append(i);
}
So from now on, we'll attached our javascript to our html instead of alerts, because alerts are frustrating and annoying to work with.
Make two divs, one should be green and the other yellow.
Loop through all the numbers between 1 and 100. Put the even numbers in the green box and the odd numbers in the yellow box.
Often times we need to check for more than just one condition.
var a = true;
var b = true;
if (a && b){
}
if(a || b){
}
if(!a && !b){
}
which will run?
var a = true;
var b = true;
var c = false;
if (a && c){
//test 1
}
if(a || c){
//test 2
}
if(a && !c){
//test 3
}
var a = 8;
var b = 5;
var c = 3;
if(a > b && c != a){
//test1
};
if((a + b) > c || c < a){
//test2
};
if(c != a || b > (a-c)){
//test3
};
Print the numbers 1 - 100, if the number is a multiple of 3 you should print "Fizz". If the number is a multiple of 5 you should print "Buzz". If the number is a multiple of 3 and 5 you should print "Fizz Buzz".
You can collect input from users using HTML form fields too.
Three very common form input fields are text, radio, and checkbox.
JSFiddle, create an input text field.
<input type='text' id='name'/>
Now, create a div and give it an id of "submit". Make the text say "Submit".
Now, when someone clicks, make alert out the text in the input field.
$('#submit').click(function(){
var input = $("#name").val();
alert(input);
}
You can collect input from users using HTML form fields too.
Three very common form input fields are text, radio, and checkbox.
<input type='text' id='name'/>
<input type='radio' name='group1' class='radio_buttons'>Option 1</input>
<input type='radio' name='group1' class='radio_buttons'>Option 2</input>
<input type='radio' name='group1' class='radio_buttons'>Option 3</input>
<input type='checkbox' id='cheese' class='checkbox_group'>Cheese</input>
<input type='checkbox' id='onions' class='checkbox_group'>Onions</input>
<input type='checkbox' id='chicken' class='checkbox_group'>Chicken</input>
Build a website that allows a user to order a pizza.
Stage one is to create a layout that has the name of your pizza shop and some pictures / text to make it look good.
15 minutes
They should be able to select small, medium, or large for their pizza size.
To do this you will need to use a new tag called an input tag.
<input type='radio' class='size' value='small'/>
10 minutes
The need to submit
(Make it look good)
<button>Submit</button>
5 minutes
So far all our javascript has been executed on page load. We are going to make a function which we call instead of just execute.
For now, just make a variable called size and set it equal to one of your sizes, then if size is small, set a price variable to the cost of a small pizza, if medium, set the price variable to to a the cost of a medium etc.
Then include tax, prompt the user for a tip, and then alert out the total cost of the order.
function orderPizza(){
var size = 'small';
if(size...
}
10 minutes
Instead of making size a static value, let's make it what ever the person clicked.
var size = $('.size').val();
10 minutes
Add an attribute called onclick and set it equal to the name of your function to your submit button.
Now have them pick a crust type and make that change the price as well.
15 minutes