This forum is now read-only. Please use our new forums! Go to forums
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
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.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
@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.
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
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