My car brand is Honda write a JavaScript function input that ask user favorite c
ID: 3822483 • Letter: M
Question
My car brand is Honda write a JavaScript function input that ask user favorite car make and allows them to input answer if the answer isn't Honda then they can contact my other coworkers. -Individually, select a car brand. Make sure each team member has a unique brand selected. -Ask the user their favorite brand of car and using the Input On your car websites, record this value. On each individual salesperson page, test the input and based on the results of this test, let the user know if you are the right person to talk to and if not, which person to contact. -This test should check if the user's value is equal to each array valueExplanation / Answer
EXPALANATIPON:
I assume team size is 5 (you,john,bear,miky,tony) and brands are audi,proche ,bmw,jaguar,honda.you being honda.
If a person enters honda then output is 'you chose the right person'
If a person enters other brand name the output will be' please conatct(name) for this brand.
here is the code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<style>
* {
font-family: sans-serif;
}
#form {
margin-top: 100px;
}
#input {
padding: 3px;
border-radius: 2px;
font-size: 16px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<center>
<form action="" id="form">
Brands: audi, bmw, jaguar, honda, porche
<br>
<br>
<input type="text" name="" id="input" placeholder="Enter Brand name">
<br>
<input type="submit" value="Submit">
<div id="result"></div>
</form>
</center>
</body>
<script type="text/javascript">
$(document).ready(function () {
$("form").on("submit", function (e) {
e.preventDefault();
var brands = [
{
c_name: 'audi',
person_name: 'John'
},
{
c_name: 'bmw',
person_name: 'Mikey'
},
{
c_name: 'jaguar',
person_name: 'Tony'
},
{
c_name: 'honda',
person_name: 'Bear'
},
{
c_name: 'porche',
person_name: 'Mark'
}];
var myBrand = 'Honda';
var getInput = $("input").val();
function findMyBrand(ary, value) {
var match;
for (var i = 0; i < ary.length; i++) {
if (ary[i].c_name == value)
return 1;
}
}
var brand_exists = findMyBrand(brands, getInput);
if (getInput.toLowerCase() == myBrand.toLowerCase()) {
document.getElementById('result').innerHTML = 'You chose the Right person';
} else if (getInput == "") {
document.getElementById('result').innerHTML = 'Please enter Brand name';
} else if ((getInput != "") && (brand_exists != 1)) {
document.getElementById('result').innerHTML = 'Please enter from given Brands';
} else {
var theIndex = -1;
for (var i = 0; i < brands.length; i++) {
if (brands[i].c_name == getInput) {
theIndex = i;
break;
}
}
document.getElementById('result').innerHTML = 'Please contact ' + brands[theIndex].person_name + ' for this brand';
}
});
});
</script>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.