/    Sign up×
Community /Pin to ProfileBookmark

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

[B]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>?
[/B]

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

[B]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]

[/B]
Section (? [5 Marks]

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

[B]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.[/B]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@HaseebjavaauthorNov 16.2015 — 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 />";

}

}

}

}
×

Success!

Help @Haseebjava spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...