Skip to content
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

Update 3.js #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 11 additions & 10 deletions 3.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// problem: why is it logging out 0? it should be 12
// since 4 * 4 is 16, 2 * 2 is 4 and 16 - 4 is 12
// fix it to log out 12!

function square(num) {
result = num * num
return result
let result = num * num;
return result;
}

result = square(4)
result2 = square(2)
var subtracted = result - result2
console.log(subtracted)
//the issues in these code is you should have to use let or const to declare the variables result and result2

//By using let or var keyword to declare result and result2,
//we ensure that each variable is scoped correctly and not overwritten by subsequent calls to the square function

let result = square(4);
let result2 = square(2);
var subtracted = result - result2;
console.log(subtracted); // Output: 12