Commit 22f4527c authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

Finish JS Assignments

parents
<html>
<head>
<title>My First Program</title>
</head>
<body>
<form>
<label for="temp">Input the temperature in fahrenheit:</label>
<input id="temperature" type="text" name="temp">
<button type="button" OnClick="getValue()">Submit</button>
</form>
<p id="demo"></p>
<script>
var getTemp;
function getValue(){
getTemp = document.getElementById("temperature").value;
}
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
console.log(getTemp);
document.getElementById("demo").innerHTML = "The temperature is " + toCelsius(77) + " Celsius.";
document.getElementById("demo").style.color = "green";
document.getElementById("demo").style.fontSize = "x-large";
</script>
</body>
</html>
<!-- <script type="text/javascript">
(function (name, session){
document.write(`Hello ${name}! Welcome to ${session}.`);
})("Alex", 'JavaScript Basics')
</script> -->
<!-- const fun = function myFunction(personName, session) {
return "Hello " + personName + "! Welcome to " + session;
}('Pradeep','JavaScript');
document.write(fun) -->
<html>
<head>
<title>My First Program</title>
</head>
<body>
<p id="sum"></p>
<script>
function fun1(a){
function fun2(b){
return (2 * a) + (2*b);
}
return fun2;
}
document.getElementById("sum").innerHTML = "The sum is " + fun1(2)(3);
</script>
</body>
</html>
<!-- <html>
<body>
<h1>JavaScript: Self Invoking Anonymous function</h1>
<code>
document.write(
((personName, session) => {
return "Hello " + personName + "! Welcome to " + session;
})('Kyle', 'JavaScript')
);
</code>
<br><br>
<script>
document.write(
((personName, session) => {
return "Hello " + personName + "! Welcome to " + session;
})('Kyle', 'JavaScript')
);
</script>
</body>
</html> -->
<html>
<head>
<title>My First Program</title>
</head>
<body>
<p id="demo"></p>
<p id="demo_forOf"></p>
<p id="demo_switch"></p>
<script>
var txt = "";
var person = {fname:"Linder", lname:"Herving", age:23};
var x;
for (x in person) {
txt += person[x] + " ";
}
document.getElementById("demo").innerHTML = txt;
let cars = ["Apple", "Banana", "Orange"];
let text = "";
for (let x of cars) {
text += x + "<br>";
}
document.getElementById("demo_forOf").innerHTML = text;
var day;
switch (new Date().getDay()) {
case 0:
day = "SUN";
break;
case 1:
day = "MON";
break;
case 2:
day = "TUE";
break;
case 3:
day = "WED";
break;
case 4:
day = "THU";
break;
case 5:
day = "FRI";
break;
case 6:
day = "SAT";
}
document.getElementById("demo_switch").innerHTML = "Today is " + day;
</script>
</body>
</html>
<html>
<head>
<title>My First Program</title>
</head>
<body>
<p id="demo_while"></p>
<p id="demo_doWhile"></p>
<p id="operators"></p>
<script>
let fruits = ["Apple", "Banana", "Orange", "Tomato"];
let text = "";
let x = 0;
while(x < fruits.length){
if(fruits[x] === "Tomato"){
text += "Otamot" + "<br>";
}else{
text += fruits[x] + "<br>";
}
x += 1;
}
var txt = "";
var i = 0;
do {
txt += "The number is " + i + "<br>";
i++;
}
while (i < 10);
let operators = "";
let sum = 10 + 5;
let product = 10 * 5;
let subtract = 10 - 5;
let division = 10 / 5
operators += sum.toString() + "<br>" + product.toString() + "<br>" + subtract.toString() + "<br>" + division.toString() + "<br>";
document.getElementById("demo_while").innerHTML = text;
document.getElementById("demo_doWhile").innerHTML = txt;
document.getElementById("operators").innerHTML = operators;
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment