Skip to content

Commit 06edab3

Browse files
author
Anna Aitchison
committed
code for playing-computer workshop
1 parent 52add02 commit 06edab3

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

playing-computer/example-0.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// WARM UP ROUND
2+
// no function declarations in here
3+
// so only one person "plays" the global frame
4+
5+
let height = 10;
6+
let length = 20;
7+
let area = height * length;
8+
console.log(`area is ${area}`);
9+
10+
height += 3;
11+
length = length * 5;
12+
13+
console.log(`height is now ${height}`);
14+
console.log(`length is now ${length}`);
15+
16+
area = height * length;
17+
console.log(`area is ${area}`);

playing-computer/example-1.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// EXAMPLE 1
2+
// now there is a global frame, and an add frame
3+
// one person will "play" the global frame
4+
// another person will "play" the add frame
5+
6+
function add(a, b) {
7+
return a + b;
8+
}
9+
10+
let x = 10;
11+
let y = 32;
12+
x = x + 1;
13+
y = y - 4;
14+
console.log("x is ", x);
15+
console.log("y is ", y);
16+
console.log(add(x, y));

playing-computer/example-2.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// EXAMPLE 2
2+
// now there will be a global frame, getFirstChar frame, getLastChar frame
3+
// one person will need to "play" one of these frames
4+
5+
const alphabet = "abcdefghijklmnopqrstuvwxyz";
6+
7+
function getFirstChar(str) {
8+
return str[0];
9+
}
10+
11+
function getLastChar(str) {
12+
const lastCharIndex = str.length - 1;
13+
return str[lastCharIndex];
14+
}
15+
16+
const firstChar = getFirstChar(alphabet);
17+
const lastChar = getLastChar(alphabet);
18+
console.log(`The first character in the alphabet is ${firstChar}`);
19+
console.log(`The last character in the alphabet is ${lastChar}`);

playing-computer/example-3.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Assign people to the different frames you'll need...
2+
3+
function convertToPercentage(decimalNumber) {
4+
const percentage = `${decimalNumber.toFixed(2) * 100}%`;
5+
return percentage;
6+
}
7+
8+
function writeRatioWithPercentage(ratio) {
9+
const firstPart = Number(ratio[0]);
10+
const secondPart = Number(ratio[2]);
11+
const allParts = firstPart + secondPart;
12+
13+
const firstPartPercentage = convertToPercentage(firstPart / allParts);
14+
const secondPartPercentage = convertToPercentage(secondPart / allParts);
15+
return `${firstPartPercentage} : ${secondPartPercentage}`;
16+
}
17+
18+
const input = "2:3";
19+
console.log(writeRatioWithPercentage(input));

0 commit comments

Comments
 (0)