dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Please Help I have a Test Tomorrow (below is practice test and test will be similar)

  1. #1
    Join Date
    Nov 2015
    Posts
    2

    Exclamation Please Help I have a Test Tomorrow (below is practice test and test will be similar)

    How do I apply the if/else statement in section B if i need to generate the alert messages? Please help me or guide me what should I do there?
    In section A, when it says it should contain a <div>, does it mean that it should also have a closing </div> element? So why in 3rd result part does he specifically mentions to insert another <div> inside a <div>?

    2. Section A [5 Marks]

    Create a directory labtest2B under the server directory on your virtual machine. Within that directory create the html file index.html. This index.html file should contain the following elements
    It should link to the JavaScript script file q2.js in the same directory

    a) It should contain a <div> containing (in order) the string "Input 1" (no quotes) followed by an <input> tag of type text with id "input1" (no quotes).

    b) It should contain a <div> containing (in order) the string "Input 2" (no quotes) followed by an <input> tag of type text with id "input2" (no quotes)

    c) It should contain a <div> containing (in order) the string "Result" (no quotes) followed by a <div> tag with id "result" (no quotes)
    It should contain a <button> with onclick value "compute()" displaying the text Compute


    [/B]
    Section (B) [5 Marks]

    In j2.js, define a function compute() that does the following

    a) It obtains the value of the input field 'input1" and converts it to a Number. If this cannot be accomplished an appropriate alert is generated and the program does nothing else. Call this number n.

    b) It obtains the value of the input field "input2" and converts it to a Number. If this cannot be accomplished an appropriate alert is generated and the program does nothing else. Call this number m.

    c) The program then replaces the innerHTML of the "result" tag with n rows of text. Rows are terminated with the "<br>" tag. Each row consists of m 'X' symbols. So if n was 2 and m was 3, the output would consist of two rows of output, each with three "X"'s in it.

  2. #2
    Join Date
    Nov 2015
    Posts
    2
    is this correct?

    Section A

    function replace(tag, value )
    { var d=document.getElementById(tag)
    if(d) {d.innerHTML=value}

    else {alert("the tag was not found")
    }
    }

    function format()
    {
    replace("salutation", "Mr Smith")
    replace("invoice", "123" )
    replace("item", "flux capacitor")
    replace("threaten", "please do not make me angry")
    }

    function clearit()
    { var bad = document.getElementById("buttons");
    while (bad.firstChild) {
    bad.removeChild(bad.firstChild);
    }
    }



    Section B

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript" src="q2.js"></script>
    </head>
    <body>
    <div>
    Input 1<input id="input1" type="text">
    </div>
    <div>
    Input 2<input id="input2" type="text">
    </div>
    <div>
    Result<div id="result"></div>
    </div>
    <button onclick="compute()">Compute</button>
    </body>
    </html>


    Section B Javascript


    function compute(){
    var n = document.getElementById("input1").value;
    var m = document.getElementById("input2").value;
    var i,j;
    if(Number(n)){

    }else{
    alert("Cannot cover input 1 to a Number");
    }
    if(Number(m)){

    }else{
    alert("Cannot cover input 2 to a Number");
    }
    for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
    result.innerHTML += "X";
    if(j == (m-1)){
    result.innerHTML += "<br />";
    }
    }
    }
    }

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