ClioSport.net

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • Due to ongoing maintenance work some features and functions (including Dark mode!) may be unavailable or visually appear differently.
  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

JavaScript help

Car  clio 182 black /gold
(i) A JavaScript program is intended to accept two numbers from a user,
then write the sum and difference of the two numbers to the browser
window. For example, if the user inputs 36 and 24 the program should
write
The sum of 36 and 24 is 60
The difference of 36 and 24 is 12
However, the current version (Figure 6) contains several errors. Your
task is to identify them, correct the program, and write a short
explanation of each of your changes.

<SCRIPT LANGUAGE="JavaScript">
// A program to find the sum and difference of two numbers
var firstNum;
varsecondNum;
firstNum = window.prompt('Please enter the first number., '');
firstNum = ParseFloat(firstNum);
secondNum = window.prompt('Please enter the second number', '');
secondNum = parseFloat(secondNum);
document.write'The sum of ' + first + ' and ' + secondNum + ' is

' + (firstNum + secondNum) + '<BR>');
document.write('The difference of ' firstNum + ' and ' +
secondNum + ' is ' + (firstNum+ secondNum) + <BR>);
</SCRIPT>
 
Yes. Im bad:( but just need another pair of eyes to go over it. It is for my uni course.
 
I've found a few but unfortunatly i'm not very good at javascript...

A few miss placed commas, full stops & spaces
 
Code:
<SCRIPT type="text/JavaScript">

// A program to find the sum and difference of two numbers

var firstNum = window.prompt("Please enter the first number");
var secondNum = window.prompt("Please enter the second number"); 

var answer = parseInt(firstNum) + parseInt(secondNum);

document.write('The sum of ' + firstNum + ' and ' + secondNum + ' is ' + answer  + '<BR>');
document.write('The difference of ' + firstNum + ' and ' + secondNum + ' is ' + (firstNum - secondNum) + '<BR>');
</SCRIPT>

I sorta improved the script aswel heh..
 
Much, much better !


Code:
<SCRIPT type="text/JavaScript">

// A program to find the sum and difference of two numbers

var firstNum = window.prompt("Please enter the first number");
var secondNum = window.prompt("Please enter the second number"); 

var answer = parseInt(firstNum) + parseInt(secondNum);

document.write('The sum of ' + firstNum + ' and ' + secondNum + ' is ' + answer  + '<BR>');
document.write('The difference of ' + firstNum + ' and ' + secondNum + ' is ' + (firstNum - secondNum) + '<BR>');
</SCRIPT>
I sorta improved the script aswel heh..
 
Back
Top