Bootstrap offers a lot of functionality. It's a library of pre-built css styles that allow us to do some impressive stuff. At it's core, it creates a grid.
<body>
<div class="row">
<div class="col-xs-4 colormered">
</div>
<div class="col-xs-4 colormered">
</div>
<div class="col-xs-4 colormered">
</div>
</div>
</body>
Javascript is all about interaction. Javascript is a programming language that allows you to "teach" computers to do specific things under different conditions.
Make a new folder on your desktop
Open Sublime Text Editor
Create a new file
Save the file in your folder, as index.html
Type Hello World, and then be sure to save.
Go to your browser, hit Control+O (command on mac) and open your file.
<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
num1 = 4
num2 = 12
num3 = 16
num4 = 1
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.
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.
The key to any good game is randomness.
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
Figure out how to round it so it is just a whole number. (google search!)
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!");
}
Add another if that says if less than 50 alert the number, 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!");
}
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");
}
}
function myFunction(p1, p2) {
return p1 * p2;
}
function timesTwo(p1, p2) {
return p1 * p2;
}
var num1 = prompt("Give me a number");
var num2 = prompt("Give me another number");
alert(timesTwo(num1, num2);
<button>Click Me</button>
Copy the code into a new file and load it up. What happens? What doesn't happen?
<button onclick="myFunction()">Click me</button>
<script>
myFunction(){
alert("hello");
}
</script>
<button onclick="myFunction()">Click me</button>
<script>
myFunction(){
alert("hello");
}
</script>
<script>
for(var i=0; i<6; i++){
alert(i);
}
</script>
<script>
for(var i=3; i<=10; i++){
alert(i);
}
</script>
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?
Computers are really good at doing things over and over again.
Instead of saying the number, say whether it's even or odd.
Loop from 1 - 5, if the number is less that 3, say "That's less than 3", if the number is three, say "3" and if the number is greater than 3, say "That's greater than 3".
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.