Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ Project
* Rock Paper Scissors

Curricula
* We might need to quickly go over and review the CSS material.. if we have time
* variables
* functions
* jQuery's selector class
* jQuery click events
* styling elements with jQuery

Style of Teaching
* Show and run the game for them first
* We should be coding with them to be more interactive - making them follow the slides would be too dull
* We could use one screen for the code and the other for the HTML page that would be displayed so they could see them side by side
124 changes: 124 additions & 0 deletions intro-to-javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Variables

* We will provide an HTML file:
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button">Click me!</button>
</body>
</html>
```
* We will add an `onlclick` event to the button and add the function between script tags in the body:
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button" onclick="sayHello()">Click me!</button>

<script>
function sayHello() {
alert("Hello, World!");
}
</script>
</body>
</html>
```
* Then, we'll take it up a notch and introduce arguments.
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button" onclick="sayHello('World')">Click me!</button>

<script>
function sayHello(x) {
var name = x;
alert("Hello, " + name + "!");
}
</script>
</body>
</html>
```
* But what if we want to ask them what their name is? We can add a prompt.
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button" onclick="sayHello()">Click me!</button>

<script>
function sayHello() {
var name = prompt("Please enter your name");
alert("Hello, " + name + "!");
}
</script>
</body>
</html>
```
* Since pressing Cancel results in the alert saying "Hello, null!" we can include an if statement:
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button" onclick="sayHello()">Click me!</button>

<script>
function sayHello() {
var name = prompt("Please enter your name");
if (name != null) {
alert("Hello, " + name + "!");
}
}
</script>
</body>
</html>
```
* Addition of the confirm() option:
```html
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Javascript Tutorial</title>
</head>
<body>
<button type="button" onclick="sayHello()">Click me!</button>

<script>
function sayHello() {
var cancelled = false;
while(cancelled == false) {
var name = prompt("Please enter name: ");
if (name == "" || name == null) {
cancelled = confirm("Are you sure you do not want to enter your name?");
} else {
cancelled = true;
alert("Hello, " + name + "!");
}
}
}
</script>
</body>
</html>
```