generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03fce56
commit bac35dc
Showing
3 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
// Predict and explain first... | ||
|
||
function multiply(a, b) { | ||
console.log(a * b); | ||
return a * b; | ||
} | ||
|
||
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
//the console does not return any value without return it will return undefined | ||
|
||
// If we want a function to return a value, we should use the return keyword. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// Predict and explain first... | ||
//The semicolon (;) following the return statement causes an immediate termination of the function. This semicolon prevents the continuation of expressions within the block and disregards the rest of the function. | ||
|
||
function sum(a, b) { | ||
return; | ||
a + b; | ||
//return; a + b; } so it will be like this | ||
return a + b; | ||
} | ||
|
||
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
// Predict and explain first... | ||
|
||
const num = 103; | ||
//Constant (const) declaration of 103 | ||
//return converts the value of the num variable to a string (using the toString() method), and then takes the last character of the string. | ||
// console.log gives last digit of any number. | ||
|
||
// This program should tell the user the last digit of each number... | ||
// Explain why getLastDigit is not working properly - correct the problem... | ||
|
||
/* The issue is that the function is not using the parameter passed to it. It always returns the last digit of the constant num, which is set to 103. The function should take a parameter and return the last digit of that parameter. */ | ||
|
||
/* | ||
const num = 103; | ||
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)}`); | ||
console.log(`The last digit of 806 is ${getLastDigit(806)}`); */ | ||
|
||
//here is my solution ; | ||
|
||
// This program should tell the user the last digit of each number. | ||
// Explain why getLastDigit is not working properly - correct the problem | ||
function getLastDigit(number) { | ||
return number.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)}`); |