0

I am being asked to create a table using javascript that displays simple arithmetic of a variable given to me by the user and I'm sure that my syntax is off inside of my document.write, but I'm not sure where and how. My error console says I'm missing a closing ')' at line 18 the end which is not true at all. I saw that in other cases it is frowned upon to use the document.write function for this purpose, but it's explicitly stated that I should do so as part of the requirements for the completion of this lab, so my sincere apologies for this transgression beforehand.

The code is below - Thanks in advance for any and all help:

<script>  
     var  e1="", e2="", e3="", e4="", e5="", e6="", e7="", e8="", e9="";

    e1 = prompt("Enter your first name in lower case", "");
    var e1u = substr(0, 1);
    e1 = e1u.toUpperCase() + e1.substr(1, e1.length-1);
    e2 = prompt(e1 + ", enter an integer from 1 to 9", "");
    e3 = prompt("Now enter 5 numbers delineated by a comma!", "");
    e4 = prompt("Now enter 3 colors delineated by a comma!");
    e5 = new date();
    e6 = e3.split(',');
    e7 = e4.split(',');
    document.write(""Today's Date = " + e5.getMonth()+1 + "/" + e5.getDay() +
    "/" + e5.getFullYear() + "\n" + "The number in e2 is " + e2 + "\n"
    + "<table><caption>Times Table for the number + e2 + "</caption>"");
    for(var i=0; i<13; i++)
    {
            document.write(""<tr>""<td>" + e2 + "</td>" + "<td>" + i + "</td>" + "<td>" + "=" + "</td>" + "<td>" + (e2 * 1) * i + "</td>""</tr>"");
    }               


</script>
4
  • where is line 18? also the compiler does not lie Commented Jul 26, 2012 at 20:05
  • I changed it to use javascript syntax hilighting and now you can clearly see the problems. Commented Jul 26, 2012 at 20:08
  • I prefer dom methods like document.createElement('table'), atleast it keeps the code clean. Commented Jul 26, 2012 at 20:08
  • 1
    new Date() - javascript is case sensitive. Commented Jul 26, 2012 at 20:11

4 Answers 4

3

I fixed the following for you:

document.write("Today's Date = " + e5.getMonth()+1 + "/" + e5.getDay() +
"/" + e5.getFullYear() + "\n" + "The number in e2 is " + e2 + "\n"
+ "<table><caption>Times Table for the number" + e2 + "</caption>");

and

document.write("<tr><td>" + e2 + "</td>" + "<td>" + i + "</td>" + "<td>" + "=" + "</td>" + "<td>" + (e2 * 1) * i + "</td></tr>");

Don't double up quotations, and use an editor with syntax high-lighting. It will save you a lot of time.

Sign up to request clarification or add additional context in comments.

Comments

0

This looks wrong:

+ "</td>""</tr>""

maybe you want

+ "</td></tr>"

Comments

0

Date(), not date()

e1.substr, not just substr and I would use substring, not substr

Missing quote after number e2

I would do it like this http://jsfiddle.net/mplungjan/eggWj/

Comments

-1

Tables must have the following nesting structure:

<table>
   <tr>
       <td> ... </td>
   </tr>
</table>

Your <caption> cannot be placed where it is and likely belongs in a TD or outside of the table completely.

2 Comments

I've never seen this used in the wild.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.