Upload
max-friel
View
6.631
Download
0
Embed Size (px)
Citation preview
Summary on Javascript coding
Document.write produces a message in a program, what is within the quotation marks will be displayed in the program for example-
(“ the total marks are”)
Summary on Javascript coding
Variables can be defined with a name, any name you choose for example... var maroon_5
Variable names are case-sensitive and should only begin with a letter/underscore. Var 6num would not work.
Variables can not include spaces
Summary on Javascript coding
ParseInt is used in coding to assign a variable to be recognised by the program. For example if you see numb=parseInt(numb) then this means that var numb will be a number you enter into the program.
Summary on Javascript coding
Mathematical operators are used to make the program perform an equation on numerical data.
*, %, -, /, + are examples of operators.
Summary on Javascript coding
Prompt is used to make the program allow the user to enter data.
Anything included in the quotation marks will displayed in the program. For example- var numb= prompt(“ enter a number here”);
Summary on Javascript coding
Other Mathematical operators
== (is equal to)
< (is less than)
> (is more than)
<= (is less than equal to)
!= (is not equal to)
>= (is greater than equal to)
Summary on Javascript coding The if statement allows the program to
provide more than one output If is always followed with { and } clauses Can include an else to add additonal outputs
based on the data for example-if( marks>3)
{
document.write (“yes”)
}
else
{
Document.write (“no”)
}
Coding activity
Instructions-Choose one of the code statements in each slide
and copy into notepad to build a program
Write a program to present the Grade for marks of a test
A) <html>
<body>
<script type="text/javascript">
b)<html>
<script ="text/javascript">
c)<html>
<body>
<script type="javascript">
Grade for marks of a test
A)var marks = prompt(enter the marks of test)
marks=parseInt(result);
b)var marks = prompt("enter the marks of test","");
marks=parseInt(marks);
c)var result = ("enter the marks of test","");
totalmarks=parseInt(marks);
Grade for marks of a test
A)if else(marks==60)
{
document.write("grade is a");
b)if(marks>=60)
{
Documentwrite=("grade is a");
c)if(marks>=60)
{
document.write("grade is a");
Grade for marks of a test
A) }
Else = (marks >=45)
{
document.write("grade is b");
b) }
else if (marks =45)
{
document.write("grade is b");
c) }
else if (marks >=45)
{
document.write("grade is b");
Grade for marks of a test
A) }
else if (marks >=30)
{
document.write("grade is c");
b) }
else if (marks >=30)
document.write("grade is c")
c) {
else if (marks >=30)
{
document.write("grade is c");
Grade for marks of a test A) }
else
{
document.write("grade is f");
}
b)
else
{
document.write("grade is f");
}
c) }
else
{
document.write(grade is f);
}
Grade for marks of a test A)<script>
</body>
</html>
b)
</body>
</html>
c)
</html>