Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions assignment/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
<header>
<h1>Unit 3, Part 3</h1>
</header>
<!-- create an ordered list with any questions you have on this week's material -->
<div id="container">
<!-- create an ordered list with any questions you have on this week's material -->
<ul>My Questions for the Week!
<ol>1. having trouble with loading my page in vs code.</ol>
<ol>2. had a bit of trouble with remembering Array but finally got it!
<ol>3. Will or can we expand our knowledge base with Prime when this course is over?</ol>
</ol>
</ul>
<div id="container">
<div class="note">
<div>
In addition to passing tests, we will be looking
Expand All @@ -38,11 +44,10 @@ <h1>Unit 3, Part 3</h1>
</div>

<!-- If you have any questions, add them in paragraph tags here! -->
<p></p>
<p>I do not have any questions at this point. Just getting really excited about the comming weeks.</p>

<!-- Used for automated testing -->
<div id="mocha"></div>
</div>
<script src="../test/test.js"></script>
</body>
</html>
93 changes: 72 additions & 21 deletions assignment/scripts/part-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ console.log('****** Part Supply *******');
// your code does what you expect!

// 1. Create a variable called 'partsNeeded' with a value of the number 40.
console.log('1. Create partsNeeded:');
let partsNeeded = 40;
console.log('Parts needed: 40');


// 2. Create a variable called 'supplyChanges' whose value is an array containing
// the following numbers: 3, 5, -6, 0, 7, 11.
console.log('2. Create supplyChanges:');
let supplyChangesArray= [3, 5, -6, 0, 7, 11];
console.log('Supply changes: 3,5,-6,0,7,11');


// 3. Create a variable called 'secondItem' and assign it the value of the second
// item in the 'supplyChanges' array.
console.log('3. Access the second value of supplyChanges:');

let secondItem = [1];
console.log('access the second value of supplyChangesArray:5');

// 4. The last value in the 'supplyChanges' array was added by mistake.
// Remove it from the array and store it inside a new variable called 'removedItem'.
console.log('4. Remove the last value from supplyChanges:');

removeItem = supplyChangesArray.push(5);
let removedItem =11;
console.log('Remove the last value from supplyChangesArray: 11');

// 5. A delivery of 25 more parts arrived. Add the value 25 to the end of the array
console.log('5. Add the value 25 into supplyChanges.');
let supplyChanges = supplyChangesArray.push
console.log('Add the value 25 into supplyChangesArray: 25');


// 6. Create three new variables named 'positives', 'negatives', and
Expand All @@ -33,38 +37,85 @@ console.log('5. Add the value 25 into supplyChanges.');
// - If the value is a positive number, push it into the 'positives' array.
// - If the value is a negative number, push it into the 'negatives' array.
// - If the value is a zero, push it into the 'zeroes' array.
console.log('6. Looping through supplyChanges to populate arrays with positive, negative, and zero values:');

let positives = [];
let negatives = [];
let zeroes = [];

for (let i = 0; i < supplyChangesArray.length; i++) {
if (supplyChangesArray[i] > 0) {
positives.push(supplyChangesArray[i]);
} else if (supplyChangesArray[i] < 0) {
negatives.push(supplyChangesArray[i]);
} else {
zeroes.push(supplyChangesArray[i]);
}
}

console.log('Looping through supplyChanges to populate arrays with positive, negative, and zero values:', positives, negatives, zeroes);




// ***** STRETCH GOALS *********************************************
// 7. Rewrite the 'for' loop from #6 as a 'for...of' loop. Instead of 'positives',
let stretchPositives = [];
let stretchNegatives = [];
let stretchZeroes = [];

for (let value of supplyChangesArray) {
if (value > 0) {
stretchPositives.push(value);
} else if (value < 0) {
stretchNegatives.push(value);
} else {
stretchZeroes.push(value);
}
}

console.log('Looping through supplyChanges to populate more arrays with positive, negative, and zero values:', stretchPositives, stretchNegatives, stretchZeroes);
// 'negatives', and 'zeroes', create three new arrays named 'stretchPositives',
// 'stretchNegatives', and 'stretchZeroes'.
console.log('7. Looping through supplyChanges to populate more arrays with positive, negative, and zero values:');
for (let value of supplyChangesArray) {
if (value > 0) {
stretchPositives.push(value);
} else if (value < 0) {
stretchNegatives.push(value);
} else {
stretchZeroes.push(value);
}
}

console.log('Looping through supplyChanges to populate more arrays with positive, negative, and zero values:', stretchPositives, stretchNegatives, stretchZeroes);
if (supplyChangesArray = 0) {
strerchZeroes = supplyChangesArray.push();
}
console.log('Looping through supplyChanges to populate more arrays with positive, negative, and zero values:');
for (let i = 0; i < supplyChangesArray.length; i++) {
totalParts += supplyChangesArray[i];
}

// 8. Create a variable called 'totalParts' and assign it a value of 0.
// Then, write a loop that adds each value of the 'supplyChanges'
// array to the 'totalParts' variable.
console.log('8. Looping through supplyChanges to calculate the sum:');

let totalParts = 0;
for (let i = 0; i < supplyChanges.length; i++){
totalParts += supplyChanges[1];
console.log('Looping through supplyChanges to calculate the sum:');
}

// 9. We have a large stash of parts in our warehouse that we
// need to box up and get ready for shipment. There are 572
// parts in total, and each box holds 7 parts.
// Create two variables:
// 1. 'parts': Set its value to 572
// 2. 'boxesFilled': Set its value to 0
// Use a 'while' loop to keep adding parts to boxes UNTIL
// no more boxes can be filled. When the loop is finished,
// the value of 'parts' should reflect how many parts are
// "left over," and the value of 'boxesFilled' should reflect
// how many boxes were filled.
console.log('9. Filling boxes with a "while" loop');


// 2. 'boxesFilled': This variable should be assigned the result of dividing 'parts' by 7.
let parts = 572;
let boxesFilled = Math.floor(parts / 7);
let leftoverParts = parts % 7;

console.log('Total parts:', parts);
console.log('Boxes filled:', boxesFilled);
console.log('Leftover parts:', leftoverParts);


// DO NOT MODIFY
Expand Down
15 changes: 15 additions & 0 deletions launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
115 changes: 115 additions & 0 deletions part-supply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
console.log('****** Part Supply *******');
// ***** REQUIRED FEATURES *********************************************
// For each question, be sure to use console.log statements to ensure that
// your code does what you expect!

// 1. Create a variable called 'partsNeeded' with a value of the number 40.
// creating a variable called partsNeeded and setting its value @ 40
//console.log(partsNeeded)

let partsNeeded = 40;
console.log('1. Parts needed: 40');


// 2. Create a variable called 'supplyChanges' whose value is an array containing
// the following numbers: 3, 5, -6, 0, 7, 11.
// creating a variable called supplyChange and setting its value to an Array called supplyChangesArray
let suppluChangesArray = [3, 5, -6, 0, 7, 11];
console.log('2. Supply changes: 3,5,-6,0,7,11');

// 3. Create a variable called 'secondItem' and assign it the value of the second
// item in the 'supplyChanges' array.
let secondItem = supplyChanges(1);
console.log('3. access the second value of supplyChangesArray 5')

// 4. The last value in the 'supplyChanges' array was added by mistake.
// Remove it from the array and store it inside a new variable called 'removedItem'.
let removedItem = supplyChangesArray.pop();
console.log('4. Remove the last value from supplyChangesArray 11');

// 5. A delivery of 25 more parts arrived. Add the value 25 to the end of the array
let supplyChanges = suppluChangesArray.
console.log('5. Add the value 25 into supplyChanges.');


// 6. Create three new variables named 'positives', 'negatives', and
// 'zeroes' whose values are empty arrays. Then, write a for loop
// that loops through the 'supplyChanges' array. For each iteration of
// the loop:
// - If the value is a positive number, push it into the 'positives' array.
// - If the value is a negative number, push it into the 'negatives' array.
// - If the value is a zero, push it into the 'zeroes' array.

let positives = [];
let negative = [];
let zero = [];
for (let i = 0; i < supplyChangesArray.length; i++) {
if (supplyChangesArray[i] > 0) {
positives.push(supplyChangesArray[i]);
} else if (supplyChangesArray[i] < 0) {
negatives.push(supplyChangesArray[i]);
} else {
zeroes.push(supplyChangesArray[i]);
}
}
console.log('6. Looping through supplyChanges to populate arrays with positive, negative, and zero values:');




// ***** STRETCH GOALS *********************************************
// 7. Rewrite the 'for' loop from #6 as a 'for...of' loop. Instead of 'positives',
// 'negatives', and 'zeroes', create three new arrays named 'stretchPositives',
// 'stretchNegatives', and 'stretchZeroes'.

console.log('7. Looping through supplyChanges to populate more arrays with positive, negative, and zero values:');


// 8. Create a variable called 'totalParts' and assign it a value of 0.
// Then, write a loop that adds each value of the 'supplyChanges'
// array to the 'totalParts' variable.
let totalParts = 0;
for (let i = 0; i < supplyChanges.length; i++)

console.log('8. Looping through supplyChanges to calculate the sum:');


// 9. We have a large stash of parts in our warehouse that we
// need to box up and get ready for shipment. There are 572
// parts in total, and each box holds 7 parts.
// Create two variables:
// 1. 'parts': Set its value to 572
// 2. 'boxesFilled': Set its value to 0
// Use a 'while' loop to keep adding parts to boxes UNTIL
// no more boxes can be filled. When the loop is finished,
// the value of 'parts' should reflect how many parts are
// "left over," and the value of 'boxesFilled' should reflect
// how many boxes were filled.
let parts = 572;
let boxesFilled = 0;
while (parts > 0)
parts = parts -7;
boxesFilled = boxesFilled +1;
console('').log('9. Filling boxes with a "while loop"');

// DO NOT MODIFY
// Used for automated testing
try {
module.exports = {
partsNeeded: typeof partsNeeded !== 'undefined' ? partsNeeded : undefined,
supplyChanges: typeof supplyChanges !== 'undefined' ? supplyChanges : undefined,
secondItem: typeof secondItem !== 'undefined' ? secondItem : undefined,
removedItem: typeof removedItem !== 'undefined' ? removedItem : undefined,
positives: typeof positives !== 'undefined' ? positives : undefined,
negatives: typeof negatives !== 'undefined' ? negatives : undefined,
zeroes: typeof zeroes !== 'undefined' ? zeroes : undefined,
stretchPositives: typeof stretchPositives !== 'undefined' ? stretchPositives : undefined,
stretchNegatives: typeof stretchNegatives !== 'undefined' ? stretchNegatives : undefined,
stretchZeroes: typeof stretchZeroes !== 'undefined' ? stretchZeroes : undefined,
totalParts: typeof totalParts !== 'undefined' ? totalParts : undefined,
parts: typeof parts !== 'undefined' ? parts : undefined,
boxesFilled: typeof boxesFilled !== 'undefined' ? boxesFilled : undefined,
}
} catch (e) {
// Do nothing
}
File renamed without changes.
File renamed without changes.
File renamed without changes.