Today is uki15th class
Today I learned javascript.
1)
<script>
txt1="What a very ";
txt1+="nice day";
document.getElementById("demo").innerHTML=txt1;
</script>
{ouput: What a very nice day}
2)
<script>
var x=10;
x+=5;
document.getElementById("demo").innerHTML=x;
</script>
{output : 15}
3)
<script>
var carName1="Volvo XC60";
var carName2="Volvo XC60";
var answer1="It's alright";
var answer2="He is called 'johnny'";
document.getElementById("demo").innerHTML=carName1+"<br>"+carName2+"<br>"+answer1+"<br>"+answer2;
</script>
{output:
Volvo XC60Volvo XC60It's alrightHe is called 'johnny'}
4)
<script>
var cars=["saab","Volvo","BMW"];
document.getElementById("demo").innerHTML=cars[0];
document.getElementById("demo1").innerHTML=cars[0]+"<br>"+cars[1]+"<br>"+cars[2];
</script>
{output: saab Volvo BMW}
5)
<script>
var person={
firstname : "Dilani",
lastname : "karthi",
age : 19,
eyecolor : "black"
};
document.getElementById("demo1").innerHTML=person.firstname+" is "+person.age+" years old.";
document.getElementById("demo").innerHTML=person.firstname+"'s eyecolor is "+person.eyecolor+".";
document.getElementById("demo2").innerHTML= person["firstname"]+" "+person["lastname"];
</script>
6)
<script>
document.getElementById("demo").innerHTML= typeof 0 +"<br>"+typeof 314 + "<br>" + typeof 3.14+ "<br>"+ typeof (3)
+"<br>" + typeof (3+4)+"<br>"+typeof "john"+"<br>"+typeof [1,2,3]+"<br>"+typeof true +"<br>"+typeof false+"<br>"+typeof {name:"john", age:34}+"<br>"
+typeof function myfun(){};
</script>
7)
<script>
function myfun(p1,p2){
return p1*p2;
}
function myfun1(p1,p2){
return (p1+p2)/2;
}
function myfun2(f){
return (5/9*(f-32));
}
document.getElementById("demo").innerHTML= myfun(1,3);
document.getElementById("demo1").innerHTML= myfun1(1,3);
document.getElementById("demo2").innerHTML= myfun2(75);
</script>
8)
<script>
var person={
firstname:"Abi",
lastname:"Karish",
age:27,
address:"jaffna"
};
document.getElementById("demo").innerHTML=person.["firstname"]+" "+person.["lastname"];
</script>
thankyou
No comments:
Post a Comment