I have a Question( Try to make 1 HTML)
I want to make some this like this.
Write a JavaScript program that will pick randomly ONE museum from a list of 10 museums in Kuala Lumpur to visit. The choices are listed below:
a) Bank Negara Money Museum (Muzium Matawang Bank Negara)
b) Biomedical Museum
c) Islamic Arts Museum Malaysia (Muzium Kesenian Islam Malaysia)
d) Maybank Numismatic Museum
e) Malaysia Telecommunications Museum (Muzium Telekomunikasi Negara)
f) National Museum (Muzium Negara)
g) National Textile Museum Kuala Lumpur (Muzium Tekstil Kuala Lumpur)
h) National Museum of History (Muzium Sejarah Nasional)
i) Royal Malaysian Air Force Museum
j) Royal Malaysian Police Museum (Muzium Polis Diraja Malaysia)
i want to use the selection statement for the choice of museum.
i want to use the Math.floor and Math.random methods to get the random number (I dont Understand).
i want my page have an html form with a simple one-line text box that should display the name of the museum.
i want have a button that when pushed will invoke a JavaScript function that randomly chooses and displays the museum name into the text box.
Re: I have a Question( Try to make 1 HTML)
Try a javascript forum. This one is for java.
Re: I have a Question( Try to make 1 HTML)
Even though, what you've tried?
Re: I have a Question( Try to make 1 HTML)
I dont really know this Java but maybe its something like this
__________________________________________________ __________
<html>
<body>
<p id="demo">Click the button to display a random number.</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
document.getElementById("demo").innerHTML=Math.ran dom();
}
</script>
</body>
</html>
__________________________________________________ _____________________
but when i click the button i would like to make a museum will randomly choose from list,
My Coding above just random number, i dont know how to make it.
Can someone help me please...
Re: I have a Question( Try to make 1 HTML)
In JavaScript (which is what your requirement is, not Java) to generate a number between 0 and 9 you'd do something like:
Code :
var index = Math.floor(Math.random() * 10);
An array of strings would look something like:
Code :
var museums=['number1', 'number2', 'number3'];
Does this give you any ideas?