Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bryant perez control flow #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
160 changes: 86 additions & 74 deletions lib/challenge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
////////////////////////////////////
///////////////////////////////////
// READ THE INSTRUCTIONS BELOW BEFORE STARTING!
////////////////////////////////////
/*
Expand All @@ -9,100 +9,97 @@
* Test your output in the browser by commenting in and out the function call (aka invocation), e.g., "prompt1()"
*
*/

/*
* Prompt 1:
*
* Create a loop that counts from 0 to 10, printing each number (including 0 and 10).
*/

// The first one has been done for you as an example!
function prompt1() {
for (let i = 0; i <= 10; i++) {
console.log(i);
console.log(i)
}
}

prompt1()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt1()

// 🌟 MAKE A COMMIT: "Complete prompt 1"

// :star2: MAKE A COMMIT: "Complete prompt 1"
/*
* Prompt 2:
*
* Create a loop that prints every even number BETWEEN 0 and 100 (not including 0 or 100).
*/

function prompt2() {
// YOUR CODE HERE
for (let i = 1; i < 100; i++) {
console.log(i)
}
}

prompt2()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt2();

// 🌟 MAKE A COMMIT: "Complete prompt 2"

// :star2: MAKE A COMMIT: "Complete prompt 2"
/*
* Prompt 3:
*
* Create a loop that counts from -5 to 5, printing each number (including -5 and 5).
*/

function prompt3() {
// YOUR CODE HERE
for (let i = -5; i <= 5; i++) {
console.log(i)
}
}

prompt3()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt3()

// 🌟 MAKE A COMMIT: "Complete prompt 3"

// :star2: MAKE A COMMIT: "Complete prompt 3"
/*
* Prompt 4:
*
* Create a loop that counts down from 10 to 0, printing each number (including 10 and 0).
*/

function prompt4() {
for (let i = 10; i > 0; i--) {
console.log(i)
}
// YOUR CODE HERE
}

prompt4()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt4()

// 🌟 MAKE A COMMIT: "Complete prompt 4"

// :star2: MAKE A COMMIT: "Complete prompt 4"
/*
* Prompt 5:
*
* Create a loop that counts down from 5 to -5, printing each number (including 5 and -5).
*/
function prompt5() {
// YOUR CODE HERE
for (let i = 5; i > -5; i--) {
console.log(i)
}
}

prompt5()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt5()

// 🌟 MAKE A COMMIT: "Complete prompt 5"

// :star2: MAKE A COMMIT: "Complete prompt 5"
/*
* Prompt 6:
*
* Create a loop that counts from 0 to 50 (inclusive) in multiples of 2 (instead of 1),
* printing each number.
*/

function prompt6() {
// YOUR CODE HERE
for (let i = 0; i <= 50; i+=2) {
console.log(i)
}
}

prompt6()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt6()

// 🌟 MAKE A COMMIT: "Complete prompt 6"

// :star2: MAKE A COMMIT: "Complete prompt 6"
/*
* Prompt 7:
*
Expand All @@ -115,13 +112,16 @@ function prompt6() {
*/
function prompt7() {
// YOUR CODE HERE
for (let i = 0; i <=100; i++) {
if (i % 5 == 0) {
console.log(`i found a ${i}. high five!`)
}
}
}

prompt7()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt7()

// 🌟 MAKE A COMMIT: "Complete prompt 7"

// :star2: MAKE A COMMIT: "Complete prompt 7"
/*
* Prompt 8:
*
Expand All @@ -133,22 +133,19 @@ function prompt7() {
* - if someNumber is between 30 and 60, print "The number is medium sized."
* - if someNumber is greater than 60, print "We got a big one!"
*/

// define someNumber here
var someNumber;

function prompt8() {
let someNumber = 0
// print someNumber to the console in your function so you can see its value
someNumber = (math.floor)(math.random()* 99) + 1
console.log(someNumber);

// YOUR CODE HERE
}

prompt8()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt8();

// 🌟 MAKE A COMMIT: "Complete prompt 8"

// :star2: MAKE A COMMIT: "Complete prompt 8"
/*
* Prompt 9:
*
Expand All @@ -159,18 +156,15 @@ function prompt8() {
* 1. C3PO
* 2. R2D2
*/

const starWars = ["Han", "C3PO", "R2D2", "Luke", "Leia", "Anakin"];

function prompt9() {
// YOUR CODE HERE
for (let i = 0; i < starWars.length; i++)
console.log(`${[i]}. ${starWars[i]}`);
}

prompt9()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt9();

// 🌟 MAKE A COMMIT: "Complete prompt 9"

// :star2: MAKE A COMMIT: "Complete prompt 9"
/*
* Prompt 10:
*
Expand All @@ -180,17 +174,17 @@ function prompt9() {
function prompt10() {
const myArray = [];
// YOUR CODE HERE

for (let i = 1; i < 100; i++)
if(i % 2 == 0)
myArray.push(i);
// don't forget to return the array after pushing the numbers into it so you can see it in the browser!
// return the array
return myArray;
}

prompt10()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// console.log(prompt10());

// 🌟 MAKE A COMMIT: "Complete prompt 10"

// :star2: MAKE A COMMIT: "Complete prompt 10"
/*
* Prompt 11:
*
Expand All @@ -199,7 +193,6 @@ function prompt10() {
*
* Hint: What does Math.floor() do?
*/

let nums = [
14,
11,
Expand Down Expand Up @@ -227,18 +220,17 @@ let nums = [
15,
12,
];

function prompt11() {
function prompt11(array) {
let median;
arguments.sort((a, b))=> {
return a-b;
}
// YOUR CODE HERE

console.log(median);
}
prompt11()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt11();

// 🌟 MAKE A COMMIT: "Complete prompt 11"

// :star2: MAKE A COMMIT: "Complete prompt 11"
/*
* Prompt 12:
*
Expand All @@ -251,37 +243,34 @@ function prompt11() {
* Inside the inner loop, print `i: ${i} / j: ${j}`
* You might need to consult Google to see examples of nested for loops!
*/

function prompt12() {
// YOUR CODE HERE
for(let i = 1; i <= 10; i++) {
for (let j = 11; j <= 20; j++) {
console.log(`i; ${i} / j: ${j}`)
}
}
}

prompt12()
// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt12();

// 🌟 MAKE A COMMIT: "Complete prompt 12"

// :star2: MAKE A COMMIT: "Complete prompt 12"
/*
* Prompt 13:
*
* Using nested loops, print all the values inside the nested arrays.
*/

let nestedArrays = [
["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"],
];

function prompt13() {
// YOUR CODE HERE
}

// COMMENT IN THE BELOW LINE OF CODE TO TEST YOUR OUTPUT IN THE BROWSER!
// prompt13();

// 🌟 MAKE A COMMIT: "Complete prompt 13"

// :star2: MAKE A COMMIT: "Complete prompt 13"
///////////////////////////////////////////
// DO NOT MODIFY CODE BENEATH THIS LINE :)
///////////////////////////////////////////
Expand All @@ -303,3 +292,26 @@ if (!this.window) {
prompt13,
};
}
white_check_mark
eyes
raised_hands
















Jot something down