Global variable conflicts with algorithm.
See original GitHub issueChallenge Factorialize a Number has an issue.
User Agent is: Mozilla/5.0 (Windows NT 5.1; rv:47.0) Gecko/20100101 Firefox/47.0
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
var count=1;
function factorialize(num) {
for(var i=1; i<=num;i++){
count= count * i;
}
return count;
}
factorialize(0);
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Alternatives To Global Variables - Anupam Chugh - Medium
Disadvantages of Global Variables · Violates Encapsulation · Unit Testing Issues · Dealing With Concurrency · Naming Conflicts.
Read more >Conflicts in Local / Global Variables can be Unproductive
Conflicts that are created for local/global variables is to be taken seriously because it decreases code productivity which causes loss of time and...
Read more >conflict between local variable and global variable - YouTube
Hi friends,In this video i covered local variable and global variable available in c language. i started with declaring local variable in ...
Read more >Why to avoid global variables in JavaScript ? - GeeksforGeeks
This indicates that global variables can be accessed from anywhere in the particular script and are not restricted to functions or blocks.
Read more >global variables conflict between TCL sourced files
It's not guaranteed that these won't conflict — they're not strongly separated — but they might work. It's definitely an easy first thing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just spend some time figuring out why my test fails and it was this problem with a global variable.
Just a thought, how about adding a note to descriptions, that “Using global variables in this test will cause the test to fail.” I think it would help in this kinda situation, but doesn’t give too many tips for an exercise.
@krishnakumar360 : Thanks for reporting this.
Your code is correct but using the
var count=1
in the global scope is causing the test cases to fail. Moving it to the function’s scope should let you pass the challenge.The reason being that we run multiple test cases in on the code, using a global var like this persists the last value and hence the test cases fail.
Nevertheless this is valid code and we should be addressing this.