0

Hi, I did a simple loop in JSFiddle but dispite the code being error free, JSFiddle doesn't run the code even though the framework is set on PureJS ?

3
Contributors
19
Replies
46
Views
2 Years
Discussion Span
Last Post by pixelsoul
0

I'm not sure what write() is but this code works here

var dr = 4;
for (i=0;i<dr;i++) {
    console.log("what");
}

If you open the console you will see it output 4 "what" there.

0

Yes the console from any modern browser. Console.log is commonly used in dev to check you variable's values and test your code.

0

I should use console log instead of JsFiddle for JS, alright thanks

I surely didnt say that or imply that. console.log is a method that allows you to write to the console. that's about it. Its not comparible to jsFiddle. If you were using jsFiddle for this purpose, then i guess you dont need jsFiddle.

I use console.log for troubleshooting. I have seen others use the alert() method instead of console.log(). The point is that if you want to see what the value of a variable is or just write to a log to check the flow of your script, it works great for that reason.

0

I never said, you said that, I was talking about myself, on the internet everything can be taken the wrong way, it's all good.

When running the loop mentioned within console.log instead of getting four statements as seen in the loop, I get instead, four "undefined" ?

0

The code that pixelsoul provided produces an output of "what" 4 times for me. Your sample code above is not the same as his with regards to the loop.

0

That is what I was referring to; the fact that in console.log I'm getting undefined four times.

0

make sure that you wrap the word "what" with quotes. otherwise, it will be undefined since you havent defined a variable called what. that's the only thing i can think of at this moment without seeing your code.

0

I did wrap my "what" word in quotes. The code is the same as posted by pixelsoul.

0

Don't know why its not working for you then. I just tried again and it appears to work for me. here is the code I tried.

<!doctype html>
<html>
<head>

<script>
var dr = 4;
for (i=0;i<dr;i++) {
    console.log("what");
}
</script>

</head>
</html>

And the results...

capture.png

0

Yes, there is no requirement to have any HTML code within your body tags. The javascript code within the script tags can run on their own.

0

This is the code I run within console.log, to be specific the window on the right in FireBug;

var dr = 4;
for (i=0;i<dr.length;i++) {
    console.log("what");
}

The error I get is undefined !

0

-_- smh

var dr = 4;
for (i=0;i<dr;i++) {
    console.log("what");
}

You don't need the length of your 'dr' variable, it is already set as an integer.

Edited by pixelsoul

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.