Hello I have some code that I need to insert some string values into but everytime I put in letters the script wont work.
<script type="text/javascript">
"use strict";
var values = [1,2,3,4,5,6,7,8,9]; /*add string values here*/
var rand = function(){
var arr = values;
var x = Math.floor((Math.random() * arr.length));
var index = arr.indexOf(arr[x]);
document.getElementById('random').value = arr[x];
if(index > -1){
arr.splice(index,1);
}
if(arr.length<1){
document.getElementById('random').value = "no more options left";
}
console.log(arr);
}
</script>
I need to add string values to where I have 'add string values here' in my comments. So I can have:
var values = [H0A0,H0A1,H0A3,H0A4,H0A5+,H1A0];
As an example. Many thanks ahead. Also I am very new to JS/PHP.
valuesshould be an array of stringsH0A0,H0A1...? If so, then put them in as strings:var values = ["H0A0","H0A1","H0A3","H0A4","H0A5+","H1A0"];