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 ?

Recommended Answers

All 19 Replies

Share your jsFiddle with us?

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

var dr = 4;
for (i=0;i<dr;i++) {

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

Your talking about, for example, firefox console.log correct ?

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

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

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.

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" ?

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.

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

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.

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

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>

var dr = 4;
for (i=0;i<dr;i++) {


And the results...


Should the console run the code successfully without HTML code ?

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.

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++) {

The error I get is undefined !

-_- smh

var dr = 4;
for (i=0;i<dr;i++) {

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

Pixelsoul - Now that code worked (4)What.

It's the exact same code I had posted originally ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.