Javascript for and while loops


#1

Hi guys,

I'm doing my own while and for loops and I keep getting an error that says 'expected identifier'.

function (f){
for (var i = 5; i >4; i--){
console.log ("This is a for loop");
myNum = false;
};

var myNum = function () {
while ( myNum < 10){
console.log ("this is a while loop");
myNum--;
myNum = false;
}
};
f();
myNum (5);

This is my code, does anyone know what I am doing wrong?

Thanks :slight_smile:


#2

@jakecahill91
-1

Have a close look at

function (f){

-2
Try the code

var m = false;
console.log( m < 4);

false has the value 0

-3
Within the myNum function you are re-assigning the variable myNum

============================================

Please read
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1

==============================================

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html <---JavaScript code-convention
http://javascript.crockford.com/survey.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
http://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function
http://stackoverflow.com/questions/6260475/how-to-the-operator


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.