Unite Family inputs from keyboard only.which means user decide the inputs
Given three objects
SampleInput 1(from user side from keyboard)
{'surname' : 'Williams', 'city': 'Columbia'}
{'dish': 'cakes'}
{'pet': 'Rocky'}
Sample Output 1(inputs from user)
Mr and Mrs Williams went to a picnic in Columbia with a boy and a pet Rocky. Mrs Williams made a special dish "cakes"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Input</title>
</head>
<body>
<p>Enter values for the father object: </p>
<input type="text" id="surname" placeholder="surname">
<input type="text" id="city" placeholder="city">
<p>Enter values for the mother object:</p>
<input type="text" id="dish" placeholder="Favourite dish">
<p>Enter values for the child object:</p>
<input type="text" id="pet"placeholder="Child's Pet'"><br><br>
<input type="button" value="Submit" id="button">
<p id="output"></p>
</body>
<script>
document.getElementById("button").addEventListener("click",()=>{
let surname = document.getElementById("surname").value;
let city = document.getElementById("city").value;
let dish = document.getElementById("dish").value;
let pet = document.getElementById("pet").value;
let father = {
"surname": surname,
"city": city
};
let mother = {
"dish":dish
};
let child = {
"pet": pet
};
let family = {...father,...mother,...child};
document.getElementById("output").innerHTML = `Mr and Mrs ${family.surname} went to a picnic in ${family.city} with a boy and a pet ${family.pet}. Mrs ${family.surname} made a special dish "${family.dish}".`;
})
</script>
</html>
Comments
Leave a comment