The most viewed items
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<script>
var names = ["Maung Maung", "Aung Aung", "Mya Mya", "Hla Hla"];
var i, txt;
txt = "<ol>";
for(i=0; i<names.length; i++){
txt += "<li>" + names[i] + "</li>";
}
txt += "</ol>";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<script>
var names = ["Maung Maung", "Aung Aung", "Mya Mya", "Hla Hla"];
var i, txt;
txt = "<ol>";
for(i in names){
txt += "<li>" + names[i] + "</li>";
}
txt += "</ol>";
document.getElementById("demo").innerHTML = txt;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<script>
function formValidate(){
var x = document.forms["myForm"]["fname"].value;
if(x == ""){
alert("Must fill out in the form");
return false;
}
}
</script>
</body>
<form action = "formvalidate1.html" method = "POST" onsubmit = "return formValidate()" name = "myForm">
<input type = "text" name = "fname">
<input type = "submit" value = "Submit">
</form>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<input id = "demo" type = "text">
<button type = "button" onclick = "jsFun()">Check Input</button>
<p id = "page"></p>
<script>
function jsFun(){
var sms, x;
sms = document.getElementById("page");
sms.innerHTML = "";
x = document.getElementById("demo").value;
try{
if(x == "") throw "empty.";
if(isNaN(x)) throw "not a number.";
x = Number(x);
if(x < 5) throw "too small.";
if(x > 10) throw "too big.";
if(x > 4 && x < 11) throw "OK.";
}
catch (err){
sms.innerHTML = "The input is " + err;
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Cdoe Testing</title>
</head>
<body>
<input id = "demo" type = "text">
<button type = "button" onclick = "jsFun()">Check Input</button>
<p id = "page"></p>
<script>
function jsFun(){
var sms, x;
sms = document.getElementById("page");
sms.innerHTML;
x = document.getElementById("demo").value;
try {
if (x == "") throw "empty.";
if (isNaN(x)) throw "not a number.";
x = Number(x);
if(x < 5) throw "too small.";
if(x > 10) throw "too big.";
if(x > 4 && x < 11) throw "OK.";
}
catch (err){
sms.innerHTML = "The Input is " + err;
}
finally{
document.getElementById("demo").value;
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<button id = "btn1">Try Now</button>
<p id = "demo1"></p>
<button id = "btn2">Try Now</button>
<p id = "demo2"></p>
<script>
var test1 = function(){
document.getElementById("demo1").innerHTML += this;
}
//window object calls the function
window.addEventListener("load", test1);
//button object calls the function
document.getElementById("btn1").addEventListener("click", test1);
var test2 = () =>{
document.getElementById("demo2").innerHTML += this;
}
//window object calls the function
window.addEventListener("load", test2);
//button object calls the function
document.getElementById("btn2").addEventListener("click", test2);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo">Inheritance Test</p>
<script>
class Car{
constructor(brand){
this.carname = brand;
}
present(){
return "I have " + this.carname;
}
}
class Model extends Car{
constructor(brand, mod){
super(brand);
this.model = mod;
}
show(){
return this.present() + " and the model is " + this.model + ".";
}
}
var myCar = new Model("Tesla", "2021");
document.getElementById("demo").innerHTML = myCar.show();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<script>
class Car{
constructor(brand){
this.carname = brand;
}
get cnam(){
return this.carname;
}
set cnam(x){
this.carname = x;
}
}
const myCar = new Car["Tesla"];
document.getElementById("demo").innerHTML = myCar;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id ="demo"></p>
<script>
class Name{
constructor(Name, City){
this.name = Name;
this.city = City;
}
}
var newName = new Name("Thet", "Yangon");
document.getElementById("demo").innerHTML = newName.name + " stays in " + newName.city + ".";
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo">What is your name and age?</p>
<button type = "button" onclick = "jsFun()">Check Name and Age</button>
<script>
function jsFun(){
class Name{
constructor(Name, Year){
this.name = Name;
this.year = Year;
}
age(){
const date = new Date();
return date.getFullYear() - this.year;
}
}
const myName = new Name("Thet", 1987);
document.getElementById("demo").innerHTML = "My name is " + myName.name + " and my age is " + myName.age() + " years old now.";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsReduce()">Total</button>
<button type = "button" onclick = "jsReset()">Reset</button>
<script>
var numbers = [302, 428, 49, 92, 84, 70, 80, 10, 3, 200];
var num = numbers.sort(function(a, b){return a - b;}).join("<br/>");
document.getElementById("demo").innerHTML = num;
function jsReset(){
document.getElementById("demo").innerHTML = num;
}
function jsReduce(){
var number2 = numbers.reduce(funReduce);
document.getElementById("demo").innerHTML = number2;
}
function funReduce(total, value){
return total + value;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsDouble()">Double</button>
<button type = "button" onclick = "jsReset()">Reset</button>
<button type = "button" onclick = "jsTriple()">Triple</button>
<script>
var numbers = [302, 428, 49, 92, 84, 70, 80, 10, 3, 200];
var num = numbers.sort(function(a, b){return a - b;}).join("<br/>");
document.getElementById("demo").innerHTML = num;
function jsReset(){
document.getElementById("demo").innerHTML = num;
}
function jsDouble(){
number2 = numbers.map(mapDouble).join("<br/>");
document.getElementById("demo").innerHTML = number2;
}
function jsTriple(vlaue){
number3 = numbers.map(mapTriple).join("<br/>");
document.getElementById("demo").innerHTML = number3;
}
function mapDouble(value){
return value*2;
}
function mapTriple(value){
return value*3;
}
</script>
</body>
</html>