<HTML> 
<HEAD> 
<TITLE>TMA 02 Q4(ii)</TITLE> 
<SCRIPT LANGUAGE = "JAVASCRIPT"> 
var loc;
var weather;
var name;

loc = window.prompt('Please enter your location',''); 
weather = window.prompt(`Please enter the weather`,``); 
name = window.prompt(`Please enter your name`,``);

document.write(`London`;` Snowing`;` Meriam`);
document.write(`<BR>` + `See you soon`)

</SCRIPT> 
</HEAD> 
<BODY> 
</BODY> 
</HTML>

Recommended Answers

All 2 Replies

Is it correct?

No!
a.) To delimit the strings you can use either DOUBLE QUOTES (") OR APOSTROPHES('). You are using the backtick(`) which is NOT correct
b.) On the document.write() you need to separate different string using a comma(,) NOT a semicolon( ; )

<HTML> 
<HEAD> 
<TITLE>TMA 02 Q4(ii)</TITLE> 
<SCRIPT type="text/javascript"> 
 
var loc = window.prompt("Please enter your location:", ""); 
var weather = window.prompt("Please enter the weather:", ""); 
var name = window.prompt("Please enter your name:", "");
 
document.write(loc+", "+weather+", "+name+"<br />See you soon!");
 
</SCRIPT> 
</HEAD> 
<BODY> 
</BODY> 
</HTML>

- The attribute of the script called 'language' is deprecated as far as I know. Use type="text/javascript" instead.

- You don't have to predefine the variables you are going to use. They live as long as the function exists, so you don't have to apply them globally.

- Don't forget DTD (strict, or transitional) from the markup! =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.