Skip to content

Commit bbd85d9

Browse files
committed
Added Assignment
1 parent 7f6911a commit bbd85d9

File tree

9 files changed

+305
-0
lines changed

9 files changed

+305
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// TODO: Create 4-String variables to introduce develop your story.
2+
// YOUR CODE GOES HERE
3+
var protagonistName = "Shrek";
4+
var storySetting = "Donkey's Sweet Shop";
5+
var protagonistObjective = "to find the gummy sharks";
6+
var storyTitle = "Shrekcellent Search";
7+
8+
// TODO: Create 3-String variables to set the time period of your story or discuss other number elements.
9+
// YOUR CODE GOES HERE
10+
var protagonistAge = 106;
11+
var year = 1600;
12+
var century = "16th century";
13+
14+
15+
// TODO: Create 1-Array variable to show a collection of items your character might have.
16+
// YOUR CODE GOES HERE
17+
var possesions =
18+
["26 silver coins", " 1 fancy fedora", " 4 banjos"];
19+
20+
// TODO: Create 1-Boolean variable to demonstrate a true or false scenario.
21+
// YOUR CODE GOES HERE
22+
var hungryForGummySharks = true;
23+
if (hungryForGummySharks === true)
24+
{
25+
var hungryForGummySharks = "Shrek is very hungry"
26+
}
27+
28+
// TODO: Print your story to the console.
29+
// YOUR CODE GOES HERE
30+
console.log (protagonistName + " loves nothing more than to snack on gummy sharks as he plays his banjo.");
31+
console.log ("They have been his favorite candy for the past " + protagonistAge + " years of his life.");
32+
console.log("But, oh no! He ran out.")
33+
console.log("Because it is the " + century + ", " + protagonistName + " can not order more scrumptious gummy sharks from amazon, so he walks to " + storySetting + ".");
34+
console.log("As he arrives, he enters the doorway with " + possesions + ", and a goal in his heart: " + protagonistObjective + ".");
35+
console.log("He begins his "+ storyTitle + " in isle "+ year + ".");
36+
console.log(hungryForGummySharks + ", so as soon as he lays his eyes on the gummy section, he snatches every single container on the shelf, pays, and bolts back home.")
37+
console.log("Thus, he was finally able to spend the rest of his day happily snacking on gummy sharks and playing his banjo...")
38+
console.log("The End.")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// TODO: Create an array variable called "words" with the following elements: 'This', 'is', 'JavaScript', 'Coding!'
2+
// YOUR CODE GOES HERE
3+
var words = ["This", "is", "JavaScript", "Coding!"]
4+
5+
// TODO: Create an empty string variable called "sentence".
6+
// YOUR CODE GOES HERE...words.1
7+
var sentence = []
8+
9+
// TODO:
10+
// 1. Create a function called "createSentence" that takes an array as an argument.
11+
// 2. In the function use a for loop to iterate through each word element of the array.
12+
// 3. Add each word to the "sentence" variable.
13+
// 4. Return the "sentence".
14+
// YOUR CODE GOES HERE
15+
function creatingSentece(array)
16+
{
17+
for(var x = 0; x< array.length; x++)
18+
{
19+
sentence+=( array[x] + " ");
20+
}
21+
22+
console.log (sentence);
23+
}
24+
25+
// TODO: Call the function "createSentence" using the console.log method.
26+
// YOUR CODE GOES HERE
27+
28+
console.log (creatingSentece(words));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<script src="example1.js"></script>
4+
<script src="example2.js"></script>
5+
<script src="example3.js"></script>
6+
<script src="example4.js"></script>
7+
8+
<div style="margin-top: 250px">
9+
<div style="width:150px; height:150px; border:3px solid #5C68B0; text-align: center; margin: 10px; float: right; margin-right: 100px;">
10+
<button onclick="checkPoint4()" style="margin-top: 60px;">Checkpoint 4</button>
11+
</div>
12+
<div style="width:150px; height:150px; border:3px solid #5C68B0; text-align: center; margin: 10px; float: right; margin-right: 100px;">
13+
<button onclick="checkPoint3()" style="margin-top: 60px;">Checkpoint 3</button>
14+
</div>
15+
<div style="width:150px; height:150px; border:3px solid #5C68B0; text-align: center; margin: 10px; float: right; margin-right: 100px;">
16+
<button onclick="checkPoint2()" style="margin-top: 60px;">Checkpoint 2</button>
17+
</div>
18+
<div style="width:150px; height:150px; border:3px solid #5C68B0; text-align: center; margin: 10px; float: right; margin-right: 100px;">
19+
<button onclick="checkPoint1()" style="margin-top: 60px;">Checkpoint 1</button>
20+
</div>
21+
</div>
22+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Description: This program is locked into an infinite loop. Your task is to run and debug the program.
3+
*
4+
* TODO: The program should exit the loop after counting down from 5 to 1. You should check to make sure the boolean statement
5+
* is being updated.
6+
*/
7+
8+
function checkPoint1() {
9+
alert1();
10+
11+
let array = [];
12+
let x = 0;
13+
14+
// TODO: Remove the bugs from the code below.
15+
function getMultiples() {
16+
while (x <= 50 && x++){
17+
18+
array.push(x * 2);
19+
}
20+
return array;
21+
}
22+
console.log(getMultiples());
23+
24+
// DO NOT CHANGE THE CODE BELOW
25+
alert2();
26+
}
27+
28+
29+
/************************************************ DONT CHANGE THE CODE BELOW ******************************************************/
30+
function alert1() {
31+
alert("Oh no! It looks like you are trapped in an infinite loop. Go to the example1.js file and work on checkpoint 1.");
32+
}
33+
34+
function alert2(){
35+
alert("Congratulations! You have passed checkpoint 1!");
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Description: This program is assigning student IDs to 5 new students but there is a bug in the code preventing the code to run
3+
* as expected. Your task is to run and debug the program using breakpoints.
4+
*
5+
* TODO: The program has error message in the console. You should read the message and debug accordingly. The final
6+
* goal is to print out a student ID for each student to the console. The ID numbers should be from 0 to 4.
7+
*/
8+
9+
function checkPoint2(){
10+
alert3();
11+
12+
// TODO: Remove the bugs from the code below.
13+
const friends = ["Rei", "Miya", "Alexis", "Ethan", "Anna"];
14+
const studentID = [];
15+
16+
for (var i = 0; i < friends.length; i++)
17+
studentID.push("JSMIT" + i);
18+
19+
console.log(studentID);
20+
21+
}
22+
// DO NOT CHANGE THE CODE BELOW
23+
alerts(studentID);
24+
25+
26+
27+
/************************************************ DONT CHANGE THE CODE BELOW ******************************************************/
28+
function alert3() {
29+
alert("All students need to get their student IDs, but it seems like the system is down. Can you help debug the system? Go to the example2.js file and work on checkpoint 2.");
30+
}
31+
32+
function alerts(studentID) {
33+
if (studentID.length == 5) {
34+
alert("Yay! You got the system running!");
35+
}
36+
else {
37+
alert("Hmmm! It seems like Rei hasn't received his ID. Keep debugging!");
38+
}
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Description: This program is calculating the amount of change given to the customer after buying groceries but there is a bug
3+
* in the code preventing the code to run as expected. Your task is to run and debug the program using the console to print
4+
* statements.
5+
*
6+
* TODO: The program currently displays NaN in the console as the returned change. You should check and make sure the function
7+
* is reading the passed parameters.
8+
*/
9+
10+
function checkPoint3(){
11+
alert4();
12+
13+
// TODO: Remove the bugs from the code below.
14+
function superMarket(cash) {
15+
let milk = 4.99;
16+
let vegetables = 15.99;
17+
let bread = 2.99;
18+
19+
let total = milk + vegetables + bread;
20+
cash = totalCash - total;
21+
22+
return cash;
23+
}
24+
25+
function main(cash) {
26+
let moneySpent = superMarket();
27+
return moneySpent;
28+
}
29+
30+
let totalCash = 50.00;
31+
console.log("Total Cash: $" + totalCash);
32+
console.log("Change Return = $" + main(totalCash));
33+
34+
35+
// DO NOT CHANGE THE CODE BELOW
36+
if (main(totalCash) < 50) {
37+
alert("Awesome work! You got the system running!");
38+
}
39+
}
40+
41+
42+
/************************************************ DONT CHANGE THE CODE BELOW ******************************************************/
43+
function alert4() {
44+
alert("The system at the supermarket doesn't seem to be working. Can you help debug the system to help calculate the total change return to the customer? Go to the example3.js file and work on checkpoint 3.");
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Description: This program is asking the user to create a new password for their account but there is a bug
3+
* in the code preventing the code to run as expected. Your task is to run and debug the program by reading the error message.
4+
*
5+
* TODO: The program has an error message in the console. You should read the message and debug accordingly.
6+
*/
7+
8+
function checkPoint4() {
9+
// TODO: Remove the bugs from the code below.
10+
let password = [ 1, 2, 3, 4, 5, 6, 7, 8, 9];
11+
12+
while (password.length != 10) {
13+
password = prompt("New password must be 10 characters:");
14+
}
15+
alert("Your new password: " + password);
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// TODO: Create a variable called "fortune" and assign a number between 0 - 10.
2+
var fortune = 3;
3+
4+
5+
// TODO: Create a fortune teller game using conditional statements and comparison operators.
6+
// Conditions
7+
// 1. If fortune is greater than or equal to 0 and less than or equal to 3, then you have a low fortune.
8+
// 2. If fortune is greater than 3 and less than or equal to 7, then you have an average fortune.
9+
// 3. If fortune is greater than 7 and less than or equal to 10, then you have a good fortune.
10+
// 4. If the fortune is out of range, then the fortune can't be read correctly.
11+
12+
if ((fortune >= 0) && (fortune <= 3)){
13+
console.log("Sorry, but you have a low fortune.")
14+
}
15+
16+
else if ((fortune >=4) && (fortune <=7)){
17+
console.log("You have an average fortune.")
18+
}
19+
else if((fortune >= 8) && (fortune <=10)){
20+
console.log("Congradulations! You've recieved a great fortune!")
21+
}
22+
else {
23+
console.log("Fortune cannot be read correctly...")
24+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// pos is the PacMan image position variable- it is set to 0 initially
2+
var pos = 0;
3+
//pageWidth is the width of the webpage. This is later used to calculate when Pac-Man needs to turn around.
4+
let pageWidth = window.innerWidth;
5+
//This array contains all the PacMan movement images
6+
const pacArray = [
7+
['./images/PacMan1.png', './images/PacMan2.png'],
8+
['./images/PacMan3.png', './images/PacMan4.png'],
9+
];
10+
11+
// this variable defines what direction should PacMan go into:
12+
// 0 = left to right
13+
// 1 = right to left (reverse)
14+
var direction = 0;
15+
16+
// This variable helps determine which PacMan image should be displayed. It flips between values 0 and 1
17+
var focus = 0;
18+
19+
// This function is called on mouse click. Every time it is called, it updates the PacMan image, position and direction on the screen.
20+
function Run() {
21+
let img = document.getElementById('PacMan');
22+
let imgWidth = img.width;
23+
focus = (focus + 1) % 2;
24+
direction = checkPageBounds(direction, imgWidth, pos, null);
25+
img.src = pacArray[direction][focus];
26+
if (direction) {
27+
pos -= 20;
28+
img.style.left = pos + 'px';
29+
} else {
30+
pos += 20;
31+
img.style.left = pos + 'px';
32+
}
33+
}
34+
// TODO: Add a Javascript setInterval() method that will call the Run() function above every 200 milliseconds. Note: in the video, Dr. Williams uses the setTimeout() method, but here we are going to use a slightly different
35+
// method called setInterval(), so that you can have practice using this method.
36+
// Inside of the Run() function you will also have to add an extra argument "pageWidth", which is declared on line 4 when you call the checkPageBounds() function below.
37+
setInterval (Run, 200);
38+
39+
// This function determines the direction of PacMan based on screen edge detection.
40+
function checkPageBounds(direction, imgWidth, pos, pageWidth) {
41+
// TODO: Complete this to reverse direction upon hitting screen edge
42+
if (direction==0 && pos + imgWidth>=pageWidth ){
43+
return direction;
44+
45+
}
46+
else if (direction==1)
47+
{
48+
direction == 0
49+
}
50+
direction = 1
51+
}
52+
function reverse()
53+
{
54+
55+
}
56+
//Please do not change
57+
module.exports = checkPageBounds;

0 commit comments

Comments
 (0)