-
-
Notifications
You must be signed in to change notification settings - Fork 171
Sprint 2 #146
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
base: main
Are you sure you want to change the base?
Sprint 2 #146
Changes from all commits
c36d5b3
fe4ebe8
03b3c5e
6dc1cb6
5e34bb5
856a3f5
3cbc91a
f2a9162
a271680
b069435
1de6b0f
2d6c264
5930178
bfdb3fb
4116ead
11078e5
e8723c0
3e7b813
1b49ee2
32dfaaa
2bbcf99
7ce5b80
6f78ed9
661fd6d
17f8b03
9b2ceee
17d1618
f519e88
8631aae
d4486d6
616ef23
a8316b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
This is just an instruction for the first activity - but it is just for human consumption | ||
We don't want the computer to run these 2 lines - how can we solve this problem? | ||
//This is just an instruction for the first activity - but it is just for human consumption | ||
//We don't want the computer to run these 2 lines - how can we solve this problem? | ||
|
||
// add comets for Line use // | ||
/* comments for many lines | ||
can use */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
let count = 0; | ||
|
||
count = count + 1; | ||
count++;; | ||
|
||
// Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
// Describe what line 3 is doing, in particular focus on what = is doing |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
// Predict and explain first... | ||
|
||
/*it will print | ||
the first console.log (a * b) which will call the function inputs 10, 32 = 320 | ||
function multiply(a, b) { | ||
console.log(a * b); | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
DEBUG*/ | ||
|
||
//The result of multiplying 10 and 32 is 320 | ||
|
||
function multiply(a, b) { | ||
return a * b; | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
|
||
// The function wasn't called initially, so it didn't display the result. | ||
// //However, it has now been called and is returning the result. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
// Predict and explain first... | ||
|
||
/*It will print a error as return is in one line and Javasript will Not | ||
read any code after that line | ||
|
||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);*/ | ||
|
||
//FIX:// | ||
|
||
function sum(a, b) { | ||
return a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
||
//The result wasn't returned because the sum of a and b wasn't included. | ||
//Now I have fixed the code, and it is returning the result |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,34 @@ | ||
// Predict and explain first... | ||
|
||
const num = 103; | ||
//const num = 103; | ||
|
||
function getLastDigit(numLast) { | ||
return numLast.toString().slice(-1); | ||
} | ||
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
||
/* This program should tell the user the last digit of each number. | ||
the function doesn’t have a parameter to receive the num variable it’s trying to process. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is true, but not complete. It doesn't have a parameter, so why is it returning 3? Where does the 3 come from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function was using the same variable every time. Adding a parameter to the function fixed it.T |
||
// Explain why getLastDigit is not working properly - correct the problem | ||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
} | ||
|
||
console.log(`The last digit of 42 is ${getLastDigit(42)}`); | ||
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
||
|
||
|
||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
}*/ | ||
// FIX | ||
|
||
/*const num = 103; | ||
|
||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
|
@@ -10,5 +38,13 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`); | |
console.log(`The last digit of 105 is ${getLastDigit(105)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); | ||
|
||
// This program should tell the user the last digit of each number. | ||
// Explain why getLastDigit is not working properly - correct the problem | ||
function getLastDigit() { | ||
return num.toString().slice(-1); | ||
} | ||
|
||
gisdellabella@Giss-MBP debug % node 2.js | ||
The last digit of 42 is 3 | ||
The last digit of 105 is 3 | ||
The last digit of 806 is 3 | ||
42 | ||
gisdellabella@Giss-MBP debug */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,16 @@ | |
// Why will an error occur when this program runs? | ||
// Try playing computer with the example to work out what is going on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think? Why is this happening? What is the fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the duplicated declaration. With this commit |
||
|
||
|
||
function convertToPercentage(decimalNumber) { | ||
const decimalNumber = 0.5; | ||
|
||
const percentage = `${decimalNumber * 100}%`; | ||
|
||
return percentage; | ||
} | ||
|
||
console.log(decimalNumber); | ||
console.log(0.5); | ||
|
||
// const decimalNumber = 0.5; | ||
// ERROR: SyntaxError: Identifier 'decimalNumber' has already been declared | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
|
||
// Predict and explain first... | ||
|
||
// this function should square any number but instead we're going to get an error | ||
function square(num) { | ||
return num * num; | ||
|
||
function square(3) { | ||
return num * num; | ||
} | ||
} | ||
console.log (square (3)) | ||
|
||
|
||
|
||
//The error was with parameter 3, which always gave me the same result. | ||
// By changing it to "num," the function now works with any number. Also 3 is used as the parameter name for the function, which is not valid in JavaScript. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this prediction bear out, or did it print undefined? Why did it do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function wasn't called initially, so it didn't display the result. However, it has now been called and is returning the result.