This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Saharsh
almost 9 years

Taking "name" manually through "console.log". Not working!

I recently added that animation on my website, though I was thinking to take the myName variable through console.log(myName) manually when the page loads but it’s not working!

Here goes my code.

HTML

...
<body onload="doAsk()">
....
<canvas id="myCanvas"></canvas>
<script src="script.js"></script>
....
</body>

JS

var red = [0, 100, 63];
var orange = [40, 100, 60];
var green = [75, 100, 40];
var blue = [196, 77, 55];
var purple = [280, 50, 60];

function doAsk(){
    var myName = prompt("Enter your name");
}

letterColors = [green, red, orange, purple, blue];
bubbleShape = "circle";
bounceBubbles();
drawName(myName, letterColors);

What’s really happening after this is that canvas is not getting loaded properly. Am I missing something?

Answer 558c9273d3292feaff0001fa

0 votes

Permalink

Hi Saharsh,

console.log() isn’t going to work, normally website visitors don’t expect to have to interact with the console.

Getting rid of the function completely and just using the following seems to work, at least in the Codecademy exercise environment it does:

var myName = prompt("Enter your name");

Just to keep tinkering with the function idea … it looks like calling doAsk onload on the body is too late - the onload won’t fire until everything is loaded, which includes main.js and by then main.js has thrown a “Uncaught ReferenceError: myName is not defined”.

oh, wait, that gives me an idea – don’t let drawname() and bouncebubbles() run until you call doAsk. - yes that works. Put those function calls inside doAsk.

points
Submitted by Judy
almost 9 years

3 comments

Saharsh almost 9 years

@AlbionsRefuge I’m sorry, I was meant by “prompt” instead “console.log”. And even I used “prompt” instead of “console.log” originally. Thanks for your explaination. Now I get to know what was error and how can I rectify it. Let me try it.

Saharsh almost 9 years

Hey! I recently tried it and it’s working! :-) Thanks for the help. You can check it here if you want: http://log.hol.es/experiment/name.htm

Judy almost 9 years

That looks great! You seem adventurous, in case you haven’t seen it yet, this thread might have something interesting for you. http://www.codecademy.com/forum_questions/533857ac631fe9794700a672