Skip to content

Commit a182d22

Browse files
committed
w3 done
1 parent 4d25d95 commit a182d22

File tree

32 files changed

+953
-0
lines changed

32 files changed

+953
-0
lines changed
24 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Do Now</title>
4+
</head>
5+
<body>
6+
<script type="text/javascript" src="functions.js"></script>
7+
</body>
8+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// functions for greeting people in different languages
2+
function english(name) {
3+
return "hello " + name;
4+
}
5+
6+
function spanish(name) {
7+
return "hola " + name;
8+
}
9+
10+
function german(name) {
11+
return "guten tag " + name;
12+
}
13+
14+
// This is another function, what is it doing?
15+
function greeting(name, language) {
16+
return language(name);
17+
}
18+
19+
var name = "adam"
20+
21+
// alert the result of using greeting
22+
var test1 = greeting(name, english); // will be set to "hello adam"
23+
var test2 = greeting(name, spanish); // will be set to what?
24+
var test3 = greeting(name, german); // will be set to what?
25+
26+
// Greeting is taking two parameters.
27+
// what is the first parameter? What type of data is it?
28+
// what is the second parameter? What type of data is it?
29+
30+
// What is happening here?
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>RPS</title>
6+
</head>
7+
8+
<body>
9+
<h1>Rock Paper Scissors</h1>
10+
<h2>User Score: <span id="user-score"></span></h2>
11+
<h2>Computer Score: <span id="computer-score"></span></h2>
12+
<form>
13+
<input id="rock" type="radio" name="play" value="rock" checked> rock<br>
14+
<input id="paper" type="radio" name="play" value="paper"> paper<br>
15+
<input id="scissors" type="radio" name="play" value="scissors"> scissors</br>
16+
</form>
17+
18+
<button onclick="update()">Shoot!</button>
19+
20+
<script src="rps.js"></script>
21+
<script src="update.js"></script>
22+
</body>
23+
24+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
console.log('yo js works');
2+
// Hint, this will create a random number betwee 0 and 3
3+
var random = Math.floor(Math.random() * 3);
4+
5+
//put your code here
6+
7+
// create a variable called userscore to keep track of your, set to 0
8+
// create a variable called computerscore to keep track of the computers score, set to 0
9+
10+
// create a variable called computerPlay to store the computers play
11+
// will be set by a function you write later
12+
13+
// create a variable called userPlay to store the users choice
14+
// will be set by a function already written in update.js based on which radio button is clicked
15+
16+
// write a function called setComputerPlay that creates the computer play, it should take no paramaters
17+
18+
// if the number is 0, set computerPlay to rock
19+
// if the number is 1, set computerPlay to paper
20+
// if the number is 2, set computerPlay to scissors
21+
// else, there is a bug
22+
23+
//test your function in the console
24+
25+
//checkGame
26+
// make a funciton called checkGame, this is being called by update.js
27+
// compare the userPlay to the computerPlay to see who wins, use if statements
28+
// alert the result, update the proper score
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
window.onload = function(){
2+
setScores();
3+
}
4+
5+
function update() {
6+
//get which value the user has checked
7+
setUserPlay();
8+
setComputerPlay();
9+
checkGame();
10+
setScores();
11+
}
12+
13+
function setUserPlay() {
14+
var inputStatus = {
15+
rock: document.getElementById('rock').checked,
16+
paper: document.getElementById('paper').checked,
17+
scissors: document.getElementById('scissors').checked
18+
}
19+
20+
for (var play in inputStatus) {
21+
if(inputStatus[play]) userPlay = play;
22+
}
23+
}
24+
25+
function setScores() {
26+
var uScore = document.getElementById('user-score');
27+
uScore.innerHTML = userscore;
28+
var cScore = document.getElementById('computer-score');
29+
cScore.innerHTML = computerscore;
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>for loop</title>
4+
</head>
5+
<body>
6+
<script type="text/javascript" src="for.js"></script>
7+
</body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alert('working')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Strings and Arrays Demo</title>
4+
</head>
5+
<body>
6+
7+
<script type="text/javascript" src="part1.js"></script>
8+
</body>
9+
</html>

week3-for-strings-arrays/3-strings-arrays/strings-arrays-demo/part1.js

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Strings and Arrays Demo</title>
4+
</head>
5+
<body>
6+
7+
<script type="text/javascript" src="part2.js"></script>
8+
</body>
9+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var breakfast = ['granola', 'yougurt', 'coffee'];
2+
var lunch = ['sandwich', 'chips'];
3+
var dinner = ['pasta', 'tomato sauce', 'garlic bread'];
4+
5+
// Array Manipulation
6+
// Without changing the code above:
7+
// - Change coffee to tea in breakfast
8+
// - Add 'hummus' to lunch
9+
// - Carbs on Carbs, remove 'garlic bread' from dinner
10+
11+
// Nested Arrays
12+
// Create a new array called 'meals', store the arrays breakfast, lunch and dinner in meals.
13+
14+
// How would you...
15+
// - Access the the the 2nd item from lunch?
16+
// - Change 'granola' to 'oatmeal'
17+
// - Add 'ice cream' to dinner?
18+
19+
// now console out the starting meals
20+
// what do you notice?
21+
22+
// if we would rather store a copy of breakfest, lunch and dinner, we can use slice()
23+
24+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Strings and Arrays Demo</title>
4+
</head>
5+
<body>
6+
7+
<script type="text/javascript" src="bands.js"></script>
8+
</body>
9+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// make an array of 5 of your favorite bands/musicians and put them inside of the array as individual items
2+
// ask the user (using prompt) for a band/artist, turn the user input lower case and then tell the user if you like the band too
3+
// hint: check to see if it is also in your array.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Beatles Albums</title>
4+
</head>
5+
<body>
6+
<h1>Open up the Console</h1>
7+
<script type="text/javascript" src="beatles.js"></script>
8+
</body>
9+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var albums = ['Meet the Beatles', 'Beatles on Sale', 'Hard Days Night', 'Seargent Peppers Lonely Heart Club Band', 'White Album']
2+
3+
//write a function called length, that prints on the length of each string inside the array
4+
5+
//BONUS, change the function to return an array of just the album title lengths
6+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Week 3
2+
3+
![strings](https://i.imgflip.com/14rgst.gif)
4+
5+
## Objective
6+
- I can use string an array functions and properties to manipulate data.
7+
- I can build functions with for loops to iterate over an array.
8+
9+
### max
10+
- Write a function called `max` that takes an array of numbers as a parameter. The function should return the largest number that is in the array.
11+
- Use the code below to test your function.
12+
```javascript
13+
var numbers = [16, 25, 4, 13, 57, 88, 102, 45]
14+
15+
console.log(max(numbers)) //should print 102
16+
```
17+
18+
### Random Return
19+
- Write a function call `randomSong` to get a random item from an array
20+
- take in an array as a parameter
21+
- return a single item
22+
- hint: remember `Math.random()`?
23+
24+
### Number of Instances
25+
-Write a function called `numTimes` that takes a string and a single character. The function should return the number of times that the character is in the array.
26+
- Use the code below to test?
27+
```javascript
28+
var testString = 'Ob-La-Di, Ob-La-Da'
29+
30+
console.log(numIn(testString, 'a')) //should print out 3
31+
console.log(numIn(testString, '-')) //should print out 4
32+
```
33+
34+
### Change Case
35+
- Write a JavaScript function called `changeCase` which accept a string as input and will swap the case of each character. For example if you input 'The Quick Brown Fox' the output should be 'tHE qUICK bROWN fOX'.
36+
- Hint: There are some string functions that will help you out. `toLowerCase()` will return the lower case version of that string. To do the opposite do `toUpperCase()`.
37+
- Use the code below to test your function.
38+
```javascript
39+
var testText = 'The Quick Brown Fox'
40+
41+
console.log(changeCase(testText)); //should print 'tHE qUICK bROWN fOX'
42+
```
43+
44+
### No Repeat
45+
- Write a JavaScript function called `cleanUp` to remove duplicate items from an array (ignore case sensitivity)
46+
- use the code below to test your function.
47+
```javascript
48+
var testArray = ['a', 'b', 'a', 'c', 'c', 'b', 'd', 'd', 'a', 'c', 'd']
49+
50+
console.log(cleanUp(testArray)); //should print ['a', 'b', 'c', 'd']
51+
```
52+
53+
### Euler 6
54+
- Ready for a challenge? Try to solve [this](https://projecteuler.net/problem=6)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Practice</title>
4+
</head>
5+
<body>
6+
7+
<script type="text/javascript" src="practice.js"></script>
8+
</body>
9+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// 1 - find the max
2+
// Write a function called `max` that takes an array of numbers as a parameter. The function should return the largest number that is in the array.
3+
4+
// uncomment to test
5+
// var numbers = [16, 25, 4, 13, 57, 88, 102, 45]
6+
// console.log(max(numbers)) //should print 102
7+
8+
9+
// 2 - Random Song
10+
// Write a function call `randomSong` to get a random item from an array
11+
// take in an array as a prameter
12+
// return a single item
13+
// hint: remember `Math.random()`?
14+
15+
// uncomment to test
16+
// var lemonade = ['Pray You Cath Me', 'Hold Up', "Don't Hurt Yourself ft. Jack White", 'Sorry', '6 Inch ft. The Weeknd', 'Daddy Lessons', 'Love Drought', 'Sandcastles', 'Forward ft. James Blake', 'Freedom ft. Kendrick Lamar, All Night', 'Formation, Lemonade Film (Script)']
17+
// console.log(randomSong(lemonade));
18+
19+
20+
// 3 - Number of Times
21+
// Write a function called `numTimes` that takes a string and a single character. The function should return the number of times that the character is in the array.
22+
23+
// uncomment to test
24+
// var testString = 'Ob-La-Di, Ob-La-Da'
25+
26+
// console.log(numIn(testString, 'a')) //should print out 3
27+
// console.log(numIn(testString, '-')) //should print out 4
28+
29+
30+
// 4 - Change Case
31+
// Write a JavaScript function called `changeCase` which accept a string as input and will swap the case of each character. For example if you input 'The Quick Brown Fox' the output should be 'tHE qUICK bROWN fOX'.
32+
// Hint: There are some string functions that will help you out. `toLowerCase()` will return the lower case version of that string. To do the opposite do `toUpperCase()`.
33+
34+
// uncomment to test
35+
// var testText = 'The Quick Brown Fox'
36+
// console.log(changeCase(testText)); //should print 'tHE qUICK bROWN fOX'
37+
38+
39+
// 5 - No Repeat
40+
// Write a JavaScript function called `cleanUp` to remove duplicate items from an array (ignore case sensitivity)
41+
42+
// uncomment to test
43+
// var testArray = ['a', 'b', 'a', 'c', 'c', 'b', 'd', 'd', 'a', 'c', 'd']
44+
// console.log(cleanUp(testArray)); //should print ['a', 'b', 'c', 'd']
45+
46+
// Challenge - Euler 6
47+
// write a function to solve this problem: https://projecteuler.net/problem=6

week3-for-strings-arrays/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Week 3
2+
3+
## Objectives
4+
- I can use string an array functions and properties to manipulate data.
5+
- I can build functions with for loops to iterate over an array.
6+
7+
## Slides
8+
[Week 3 Slides](https://docs.google.com/presentation/d/14iFl7KczbFn3Wj2pagHldpgxuehngpjmXy289TfQzSw/edit?usp=sharing)
9+
10+
## Homework
11+
[String and Array Function Practice](https://github.com/ADDA-js/F_2016_JS_HW/tree/master/w3-strings-arrays)
12+
13+
## Resources
14+
[Functions](http://eloquentjavascript.net/03_functions.html)
15+
[Array Reference](http://www.w3schools.com/jsref/jsref_obj_array.asp)
16+
[String Reference](http://www.w3schools.com/jsref/jsref_obj_array.asp)
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
<title>Array Sandbox</title>
4+
</head>
5+
<body>
6+
<p>Open the console.</p>
7+
<p>Type <code>animals</code>, you should see the array from the js file</p>
8+
<ul>
9+
<li><code>animals.length</code></li>
10+
<li><code>animals[1]</code></li>
11+
<li><code>animals[3]</code></li>
12+
<li><code>animals.indexOf('bear')</code></li>
13+
<li>and more...</li>
14+
</ul>
15+
<p>Full list of array functions <a href='http://www.w3schools.com/jsref/jsref_obj_array.asp'>here</a></p>
16+
17+
<script type="text/javascript" src='array.js'></script>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)