AIDS Meanstack Dev: Lab3
Write a JavaScript program to find the area of a circle using radius (var and let - reassign and observe the difference with var and let) and PI (const)
<html>
<body>
<h1>Area of a circle</h1>
Enter the radius for your circle:
<input type="text" id="txtRadius" />
<input type="button" value="Calculate" onClick=CalculateArea() />
<script>
function CalculateArea() {
/* var and let are both used for variable declaration in javascript but the difference between them is that var is function scoped and let is block scoped. Variable declared by let cannot be redeclared and must be declared before use whereas variables declared with var keyword are hoisted.*/
// var radius = document.getElementById('txtRadius').value;
let radius = document.getElementById('txtRadius').value;
alert("The area of the circle is00 " + (radius * radius * Math.PI));
}
</script>
</body>
</html>
Write JavaScript code to display the movie details such as movie name, starring, language, and ratings. Initialize the variables with values of appropriate types. Use template literals wherever necessary.
<html>
<body>
<h1>Movie Details</h1>
<script>
function Movie() {
let name = "Swamy Vivekananda";
let starring = `Benarji
Sita
Rajesh
Dhawan`;
let language = "telugu";
let ratings = 4.0;
let details=`Movie:${name},rating:${ratings}`
let det2=`language:${language},starring:\n${starring}`;
alert(details+det2);
}
</script>
<input type="button" value="get Movie Details" onClick=Movie() />
</body>
</html>
Write a JavaScript code to book movie tickets online and calculate the total price based on Page 52 of 66 the 3 conditions: (a) If seats to be booked are not more than 2, the cost per ticket remains Rs. 150. (b) If seats are 6 or more, booking is not allowed. (c) If seats are more than 2 and less than or equal to 6 apply 10% discount
<!DOCTYPE html>
<html>
<body>
<input type="number" id="no" />
<input type="button" value="calculate" onClick="find()" />
<script>
function find()
{
alert("hi");
n=document.getElementById("no").value;
if(n<=2)
{
total=n*150;
alert("total price of tickets is "+total);
}
else if((n>2)&&(n<6))
{
total=n*150*0.9;
alert("total price of tickets is "+total);
}
else
{
alert("booking not allowed");
}
}
</script>
</body>
</html>
Comments
Post a Comment