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

Druzhinina_Anna_Control_Flow_HW #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
143 changes: 95 additions & 48 deletions lib/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ function prompt1() {
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"

console.log("🚀 Complete prompt 1 ");
/*
* Prompt 2:
*
Expand All @@ -36,42 +36,55 @@ function prompt1() {

function prompt2() {
// YOUR CODE HERE
for (let i = 1; i < 100; i++) {
if (i % 2 == 0) {
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"

console.log("🚀 Complete prompt 2 ");
/*
* Prompt 3:
*
* Create a loop that counts from -5 to 5, printing each number (including -5 and 5).
*/

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

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

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

console.log("🚀 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"
console.log("🚀 Complete prompt 4 ");

/*
* Prompt 5:
Expand All @@ -80,13 +93,16 @@ function prompt4() {
*/
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"

console.log("🚀 Complete prompt 5 ");
/*
* Prompt 6:
*
Expand All @@ -96,13 +112,16 @@ function prompt5() {

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"

console.log("🚀 Complete prompt 6 ");
/*
* Prompt 7:
*
Expand All @@ -115,13 +134,18 @@ 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"

console.log("🚀 Complete prompt 7 ");
/*
* Prompt 8:
*
Expand All @@ -135,20 +159,28 @@ function prompt7() {
*/

// define someNumber here
var someNumber;
let someNumber = Math.floor(Math.random() * 101);

function prompt8() {
// print someNumber to the console in your function so you can see its value
console.log(someNumber);

// YOUR CODE HERE
if (someNumber < 30) {
console.log(`That's a small number!`);
} else if (someNumber >= 30 && someNumber <= 60) {
console.log(`The number is medium sized.`);
} else if (someNumber > 60) {
console.log(`We got a big one!`);
}
}

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

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

console.log("🚀 Complete prompt 8 ");
/*
* Prompt 9:
*
Expand All @@ -164,13 +196,16 @@ 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"

console.log("🚀 Complete prompt 9 ");
/*
* Prompt 10:
*
Expand All @@ -179,17 +214,24 @@ function prompt9() {
*/
function prompt10() {
const myArray = [];
for (let i = 1; i < 100; i++) {
if (i % 2 == 0) {
myArray.push(i);
}
}
console.log(myArray);
// YOUR CODE HERE

// 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"
console.log("🚀 Complete prompt 10 ");

/*
* Prompt 11:
Expand All @@ -201,43 +243,37 @@ function prompt10() {
*/

let nums = [
14,
11,
16,
15,
13,
16,
15,
17,
19,
11,
12,
14,
19,
11,
15,
17,
11,
18,
12,
17,
12,
71,
18,
15,
12,
14, 11, 16, 15, 13, 16, 15, 17, 19, 11, 12, 14, 19, 11, 15, 17, 11, 18, 12,
17, 12, 71, 18, 15, 12,
];

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

if (nums.length % 2 != 0) {
//odd case
//find midle index
let indexMedian = Math.floor(nums.length / 2);
median = nums[indexMedian];
} else {
//even case
//find midle index
let indexMedian = Math.floor(nums.length / 2);
median = Math.floor(nums[indexMedian] + nums[indexMedian + 1]) / 2;
}
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"
console.log("🚀 Complete prompt 11 ");

/*
* Prompt 12:
Expand All @@ -254,13 +290,18 @@ function prompt11() {

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}`);
}
}
}

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

prompt12();
// 🌟 MAKE A COMMIT: "Complete prompt 12"

console.log("🚀 Complete prompt 12 ");
/*
* Prompt 13:
*
Expand All @@ -275,13 +316,19 @@ let nestedArrays = [

function prompt13() {
// YOUR CODE HERE
for (let i = 0; i < nestedArrays.length; i++) {
let a = nestedArrays[i];
for (let j = 0; j < a.length; j++) {
console.log(nestedArrays[i][j]);
}
}
}

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

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

console.log("🚀 Complete prompt 13 ");
///////////////////////////////////////////
// DO NOT MODIFY CODE BENEATH THIS LINE :)
///////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Control Flow Practice</title>
<script src="challenge.js" defer></script>
</head>
<body>
<p>Check in your console</p>
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/flat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/he

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nanoid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading