Question:
Need help with Javascript!!?
anonymous
2011-08-30 19:17:14 UTC
my javascript teacher asked us use this function and to figure out was was wrong with it using the javascript debugger in our webbrowser. He sais there was three things wrong with it and each time we used the debugger it would find one of the errors and we would have to copy and paste the error into an email to prove we did it. here is the function:

// declare this variable outside of your functions
currentspecial = 1 // selects which item that is "on special"

function displayspecial() {

if (currentspecial == 1) {
alert("The current special is #1)
}
if (currentspecial == 2 {
alert("The current special is #2")
}
if (currentspecial == 3 ) {
alert("The current special is #3"
}
currentspecial = currentspecial + 1
if (currentspecial > 3) {
currentspecial = 1
}

}

Now I have found most of what is wrong with it by just looking at it however I cannot figure out how to use the javascript debugger in mozilla firefox or IE and get an error back ( or 3! ) in which I can copy and paste into an email. If anyone can plz explain this too me I would be most grateful. Thank You!
Six answers:
George3
2011-08-30 20:08:53 UTC
Your teacher gave you no guidance on which debugger to use or how to set it up?



1. Paste the code into an almost empty HTML page (which has just , , and takes.

2. If you are using Firefox type Ctrl+Shift+J to display the Error Console (technically not a js debugger, but it will show js errors) and is simpler than installing Firebug - although I highly recommend you check out Firebug and the Web Console (Ctrl+Shift+K) later.

3. Clear the Error Console

4. Load the HTML page in the browser.

5. The first error is:



Error: unterminated string literal

Source File: file:///C:/.../someHTMLpage.html

Line: 11, Column: 6

Source Code:

alert("The current special is #1)
David
2011-08-31 06:00:58 UTC
Not only did you miss a closing double-quotation mark in your first alert, you left out an end-parenthesis on your second if statement and your third alert invocation; it was the first thing I noticed. Nobody else noticed because their JS error consoles break at the first error. Note: use the "else if" statement after your first if statement and for the rest since you are identifying the same parameter. Use semi-colons where needed as well. Also, use JSLint on jsFiddle to check for syntactical errors. http://www.jsfiddle.net



Here is how your code should look: http://jsfiddle.net/M4tJp/
anonymous
2016-10-20 08:30:49 UTC
you're taking a type and you may desire to earnings Javascript? Then do no longer ask for an entire answer. Your instructor will probable have the means to tell newbie code from expert code. All you may desire to do is how you may write down a loop and use an "if" fact with a modulus operator.
Here we go
2011-08-30 19:51:28 UTC
current special is declared outside the function,

So it will not be working inside the function.



no variable declared "currentspecial"
green meklar
2011-08-30 19:45:42 UTC
You seem to be missing some double quote marks and brackets. Fix that first, then see if you still have a problem.
Tapendra Khadka
2011-08-30 19:24:12 UTC
its make easy to open site on my mobile phone so javascript need to me.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...