Latihan Soal Asp Net Minggu 2
Latihan Soal Asp Net Minggu 2
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Latihan 1 Form</title>
</head>
<body>
@{
if (IsPost)
{
string bil1 = Request["Bil1"];
string bil2 = Request["Bil2"];
int hasil = bil1.AsInt() + bil2.AsInt();
<form method="post" action="">
Bilangan 1 :<br>
<input type="text" name="CompanyName" value="@bil1"><br>
Bilangan 2 :<br>
<input type="text" name="ContactName" value="@bil2"><br>
Hasilnya :<br>
<input type="text" name="ContactName1" value="@hasil"><br><br>
</form>
}
else
{
<form method="post" action="">
Bilangan 1 :<br>
<input type="text" name="Bil1" value=""><br>
Bilangan 2 :<br>
<input type="text" name="Bil2" value=""><br><br>
<input type="submit" value="+" class="submit">
</form>
}
}
</body>
</html>
Latihannya, Buatlah Form, untuk menghitung Luas Bangun Datar Sbb :
While Loop :
<html>
<body>
@{
var i = 0;
while (i < 5)
{
i += 1;
<p>Line @i</p>
}
}
</body>
</html>
Array :
@{
string[] members = {"Jani", "Hege", "Kai", "Jim"};
int i = Array.IndexOf(members, "Kai")+1;
int len = members.Length;
string x = members[2-1];
}
<html>
<body>
<h3>Members</h3>
@foreach (var person in members)
{
<p>@person</p>
}
<p>The number of names in Members are @len</p>
<p>The person at position 2 is @x</p>
<p>Kai is now in position @i</p>
</body>
</html>
If Condition :
@{var price=50;}
<html>
<body>
@if (price>30)
{
<p>The price is too high.</p>
}
</body>
</html>
If Else Condition :
@{var price=20;}
<html>
<body>
@if (price>30)
{
<p>The price is too high.</p>
}
else
{
<p>The price is OK.</p>
}
</body>
</html>
Else If Condition :
@{var price=25;}
<html>
<body>
@if (price>=30)
{
<p>The price is high.</p>
}
else if (price>20 && price<30)
{
<p>The price is OK.</p>
}
else
{
<p>The price is low.</p>
}
</body>
</html>
Switch Condition :
@{
var message="";
var weekday=DateTime.Now.DayOfWeek;
var day=weekday.ToString();
}
<html>
<body>
@switch(day)
{
case "Monday":
message="This is the first weekday.";
break;
case "Thursday":
message="Only one day before weekend.";
break;
case "Friday":
message="Tomorrow is weekend!";
break;
default:
message="Today is " + day;
break;
}
<p>@message</p>
</body>
</html>