www.webdeveloper.com
Results 1 to 8 of 8

Thread: Help for basic Javascript exercises.

  1. #1
    Join Date
    Oct 2012
    Posts
    8

    Help for basic Javascript exercises.

    Hi, I'm new in this forum. I would like to please you help in some basic javascript exercises in which I don't know how to do.

    1.The first exercise requires me : Use a loop to create a table with 3 columns. The first column should have the numbers from 10 to 20. The second column should have the number times 3. The third column should have the number divided by 3.

    2. Using statements IF: Assume the variable "mclass" contains the class of a movie.
    Purpose: determine how long you can keep the movie. Put this information in the variable "rentl"
    If the class of the movie is "c " you can keep the movie for 2 weeks otherwise only 1 week.



    Thank you very much for your help .

  2. #2
    Join Date
    Nov 2010
    Posts
    1,084
    you would be better served showing us what you have attempted already and asking questions about specific problems that you are having.

    If we simply do your homework for you how are you ever going to learn?

  3. #3
    Join Date
    Oct 2012
    Posts
    8
    Here is the one:

    <script text="javascript">

    function num10to20 (){
    for (var number=10; number<=20; number++)
    }
    function numtimes3(){
    for (var number=10; number<=20; number+*3)
    }
    function numdiv3(){
    for (var number=10; number<=20; number+/3)
    }
    </script>


    <center>
    <table border>
    <tr>
    <td><script>num10to20();</script> </td>
    <td><script>numtimes3(); </script> </td>
    <td><script> numdiv3();</Script></td>
    </tr>

    </table>
    </center>

  4. #4
    Join Date
    Oct 2012
    Posts
    8
    For the second one I know how to make it like this but I've to add the variable rentl and I don't know how to associate it :/

    <html>
    <body>
    <script>

    var mclass = prompt ("What kind of movie do you wanna rent", "A, B, C, D");


    if (name=="C"){

    alert("You can rent this movie for 2 weeks");
    }else{


    alert ("You can rent this movie for 1 week");

    }

    </script>
    </html>

    Also when I'm writing C ritght now it's still saying 1 week instead of 2 :/

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    I am thinking you might be misunderstanding what the expected table from exercise #1 would be. When I read the description it sounded to me like your output might look something like:

    Code:
    <table border>
    <tr>
    <td>10</td>
    <td>30</td>
    <td>3.33</td>
    </tr>
    <tr>
    <td>11</td>
    <td>33</td>
    <td>3.66</td>
    </tr>
    <tr>
    <td>12</td>
    <td>36</td>
    <td>4</td>
    </tr>
    </table>

  6. #6
    Join Date
    Jan 2009
    Posts
    3,346
    For your attempt at the second one it looks like you might have a typo causing it to behave other than expected.

    var mclass = prompt ("What kind of movie do you wanna rent", "A, B, C, D");

    if (name=="C"){
    Assigning variables in JavaScript:

    The below creates a new variable called "myVar" and assigns a value of "assigned" to it:
    Code:
    var myVar = "assigned";

  7. #7
    Join Date
    Sep 2011
    Location
    Bristol, England, United Kingdom
    Posts
    192
    If I understand the first question right, you are required to create a table within a loop by dynamically manipulating the DOM (document object model). To do this you need to use the createElement() function.

    It's actually a little trickier than you would think and probably not something you'd figure out as a beginner. If you follow strict standards, you'll also need to create table head and table body elements. I've created a comprehensive solution which you can play with: http://jsfiddle.net/DUMnb/2//
    Last edited by George88; 10-18-2012 at 05:36 PM.

  8. #8
    Join Date
    Sep 2011
    Location
    Bristol, England, United Kingdom
    Posts
    192
    Note: I can no longer edit my post above, but the URL is incorrect. The trailing slash should be removed: http://jsfiddle.net/DUMnb/2/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles