Skip to content

Commit

Permalink
debug done
Browse files Browse the repository at this point in the history
  • Loading branch information
zelihapala committed Nov 12, 2023
1 parent 03fce56 commit bac35dc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
5 changes: 4 additions & 1 deletion week-2/debug/0.js
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.
5 changes: 3 additions & 2 deletions week-2/debug/1.js
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)}`);
25 changes: 21 additions & 4 deletions week-2/debug/2.js
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)}`);

0 comments on commit bac35dc

Please sign in to comment.