Skip to content

Commit 409b453

Browse files
committed
array-testing.js and loop chapter exercises
1 parent 5e4651d commit 409b453

File tree

9 files changed

+37
-9
lines changed

9 files changed

+37
-9
lines changed

arrays/studio/array-string-conversion/array-testing.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ function determineDelimiter(str) {
2323
//2)
2424
function reverseCommas() {
2525
//TODO: 1. create and instantiate your variables.
26-
let check; //I did this in step 1 I think.
26+
let check;
27+
2728

2829
//TODO: 2. write the code required for this step
29-
let output = strings[0].split(',').reverse().join(',');
30+
output = strings[0].split(',').reverse().join(',');
3031

3132
//NOTE: For the code to run properly, you must return your output. this needs to be the final line of code within the function's { }.
3233
return output;
Binary file not shown.

how-to-write-code/Comments.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This demo shows off comments!
22

3-
// console.log("This does not print.");
3+
console.log("This does not print.");
44

55
console.log("Hello, World!"); // Comments do not have to start at the beginning of a line.
66

@@ -10,3 +10,13 @@
1010
comments. */
1111

1212
console.log("Comments make your code more readable by others.");
13+
14+
//This is a single line comment
15+
/*
16+
This
17+
is
18+
a
19+
multi-line
20+
comment
21+
*/
22+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
console.log("Some Programming Languages:");
22

33
console.log("Python\nJavaScript\nJava\nC#\nSwift");
4+
5+
console.log("This\nadds\na\nnew\nline");
6+
console.log("This\tadds\ta\tnew\ttab");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Experiment with this loop by modifying each of the following: the variable initialization, the boolean condition, and the update expression.
22

3-
for (let i = 0; i < 51; i++) {
3+
for (let i = 0; i < 10; i++) {
44
console.log(i);
55
}

loops/chapter-examples/Reversing-a-String.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ let str = "blue";
22
let reversed = "";
33

44
for (let i = 0; i < str.length; i++) {
5-
reversed = str[i] + reversed;
5+
reversed = str[i] + reversed; //by putting the string first and the "" second , each index gets added to the BEGINNING of "" starting with b
66
}
77

8-
console.log(reversed);
8+
console.log(reversed);
9+
10+
console.log(str.split(''));
11+
console.log(str.split('').reverse());
12+
console.log(str.split('').reverse().join(''));
13+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
// create an array variable containing the names
2+
let family = ['Shawn', 'Rebecca', 'Fancy', 'James']
23

34
// write a for loop that prints each name on a different line
5+
for (let i = 0; i < family.length; i++) {
6+
console.log(family[i]);
7+
}
8+
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// Create a string variable containing your name.
2+
let str = 'Lori';
23

3-
4-
// Write a for loop that prints each character in your name on a different line.
4+
// Write a for loop that prints each character in your name on a different line.
5+
for (let i = 0; i < str.length; i++) {
6+
console.log(str[i]);
7+
8+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let i = 0;
22

3-
while (i < 51) {
3+
while (i < 10) {
44
console.log(i);
55
i++;
66
}

0 commit comments

Comments
 (0)