The most viewed items
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo">Sort Numberically</p>
<button type = "button" onclick = "jsSort()">Sort</button>
<button type = "button" onclick = "jsReverse()">Reverse</button>
<script>
var numbers = [400, 40, 20, 200, 93, 49];
document.getElementById("demo").innerHTML = numbers.join("<br />");
function jsSort(){
var sort = numbers.sort(function(a,b){return a - b;}).join("<br />");
document.getElementById("demo").innerHTML = sort;
}
function jsReverse(){
var reverse = numbers.sort(function(a,b){return b - a;}).join("<br />");
document.getElementById("demo").innerHTML = reverse;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsSort()">Sort</button>
<button type = "button" onclick = "jsReverse()">Reverse</button>
<script>
var cities = ["Yangon", "Mandalay", "Naypyidaw", "Meikhtila", "Bagan"];
document.getElementById("demo").innerHTML = cities.join(" * ");
function jsSort(){
var sort = cities.sort().join(" * ");
document.getElementById("demo").innerHTML = sort;
}
function jsReverse(){
var reverse = cities.reverse().join(" * ");
document.getElementById("demo").innerHTML = reverse;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsRandom()">Sort Now</button>
<script>
var numbers = [300, 40, 83, 49, 92, 200, 79];
document.getElementById("demo").innerHTML = numbers.join("<br />");
function jsRandom(){
var random = numbers.sort(function(a, b){return 0.5 - Math.random();});
document.getElementById("demo").innerHTML = random.join("<br />");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "findMax()">Find Max</button>
<button type = "button" onclick = "jsReset()">Reset</button>
<button type = "button" onclick = "findMin()">Find Min</button>
<script>
var numbers = [200, 30, 400, 50, 1000, 70, 20, 100];
document.getElementById("demo").innerHTML = numbers.join("<br/>");
function jsMax(arr){
return Math.max.apply(null, arr);
}
function jsMin(arr){
return Math.min.apply(null, arr);
}
function findMax(){
document.getElementById("demo").innerHTML = jsMax(numbers);
}
function findMin(){
document.getElementById("demo").innerHTML = jsMin(numbers);
}
function jsReset(){
document.getElementById("demo").innerHTML = numbers.join("<br />");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "findMax()">Find Max</button>
<button type = "button" onclick = "numReset()">Reset</button>
<button type = "button" onclick = "findMin()">Find Min</button>
<script>
var numbers = [200, 30, 400, 50, 1000, 70, 20, 100];
document.getElementById("demo").innerHTML = numbers.join("<br />");
function jsMax(arr){
var len = arr.length;
var max = -Infinity;
while(len--){
if(arr[len] > max){
max = arr[len];
}
}
return max;
}
function jsMin(arr){
var len = arr.length;
var min = Infinity;
while(len--){
if(arr[len] < min){
min = arr[len];
}
}
return min;
}
function findMax(){
document.getElementById("demo").innerHTML = jsMax(numbers);
}
function findMin(){
document.getElementById("demo").innerHTML = jsMin(numbers);
}
function numReset(){
document.getElementById("demo").innerHTML = numbers.join("<br/>");
}
</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"></p>
<script>
var myName = {firstName : "Thet", middleName : "Naing", lastName : "Win"};
document.getElementById("demo").innerHTML = myName.firstName;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<script>
var cities, clen, text, i;
cities = ["Yangon", "Mandalay", "Naypyidaw", "Meikhtila"];
clen = cities.length;
text = "<ul>";
for(i=0; i<clen; i++){
text += "<li>" + cities[i] + "</li>";
}
text += "</ul>";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo">forEach Loop</p>
<script>
var cities, text;
cities = ["Yangon", "Mandalay", "Naypyidaw", "Meikhtila"];
text = "<ul>";
cities.forEach(jsFunction);
text+= "</ul>";
function jsFunction(value){
text += "<li>" + value + "</li>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo1"></p>
<p id = "demo2"></p>
<script>
//good habit in crating array
var a = ["aaa", "bbb", "ccc", "ddd"];
document.getElementById("demo1").innerHTML = a;
//bad habit in creating array
var b = new Array("aaa", "bbb", "ccc", "ddd");
document.getElementById("demo2").innerHTML = b;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo1"></p>
<p id = "demo2"></p>
<script>
var a = ["aaa", "bbb", "ccc", "ddd"];
a[0] = "eee";
document.getElementById("demo1").innerHTML = a;
var b = new Array("aaa", "bbb", "ccc", "ddd");
document.getElementById("demo2").innerHTML = b[2];
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo">forEach Loop</p>
<script>
var cities, text;
cities = ["Yangon", "Mandalay", "Naypyidaw", "Meikhtila"];
text = "<ul>";
cities.forEach(jsFunction);
text+= "</ul>";
function jsFunction(value){
text += "<li>" + value + "</li>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>