In: Computer Science
I need to answer the the following questions in Javascript;
------------------------------------------------------------------------------------------------------------------------
3 Buttons to display “Lion”, “Tiger” and “Leopard” in a line and display textfield on next line
When“Cat” button is clicked the following 3 things will perform
Display text field “User clicks Lion”;
Under the text field display a message “Lion is clicked”;
Under the message, a photo of a lion is displayed. other buttons will work in a similar logic.
------------------------------------------------------------------------------------------------------------------------
Display the pictures of following “Lion”, “Tiger” and “Leopard”.
When users click on the “Lion” pic., alert window displays warning “Please do not click me, click the Leopard”.
When users click on the “Tiger” pic, alert window displays warning “Please do not click me, click the Leopard”
When users click on the “Leopard” pic, the leopard will jump over the Lion and Tiger, meaning that in the beginning it shows Lion Tiger Leopard, when users click the Leopard then it becomes Leopard Lion Tiger, and users click the leopard again then it becomes Lion Tiger Leopard, etc.
-----------------------------------------------------------------------------------------------------------------------
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new web page with name "lionTiger.html" is created, which contains following code.
lionTiger.html :
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>Lion , Tiger , Leopard</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type="button" value="Lion" onclick="ClickText('Lion')">
<input type="button" value="Tiger" onclick="ClickText('Tiger')">
<input type="button" value="Leopard" onclick="ClickText('Leopard')">
<br><br>
<!-- textbox to display text -->
<input type="text" id="txtSample"/>
<!-- para to display text -->
<p id="samplePara"></p>
<br><br>
<!-- img -->
<img id="img" width="200" height="200"/>
<!-- <script> is used for javascript -->
<script>
function ClickText(animal)
{
//display text in the textbox
document.getElementById("txtSample").value="User clicks "+animal;
//create element p
document.getElementById("samplePara").innerHTML=animal+" is clicked";//display text
document.getElementById("img").src=animal+".jpg";//display image
}
</script>
</body>
</html>
======================================================
Output : Open web page lionTiger.html in the browser and will get the screen as shown below
Screen 1 :lionTiger.html , screen when lion button is clicked
Screen 2 :lionTiger.html , screen when tiger button is clicked
Screen 3 :lionTiger.html , screen when leopard button is clicked
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.