HTML and Java script
Is there a way to delete an element of an array?
For example when I click this first button then a random word will appear then when I click this second button then the randomized word will be deleted or removed from the array.
here is the portion of the code
<button class="wew" onclick="thesisFinal()"><i
class="fa fa-play-circle">
Start</i></button></div>
<button
class="wew" onclick="removeThesis()"><i class="fa
fa-play-circle">
Start</i></button></div>
<p
id="thesisget">Click to generate</p>
</div>
</div>
<script>
var
thesis=["car","waybipt","wew","aioweaio","awuiegauega","aiowehauiehauiw","aopwiheioaheauiowhe","cajicnajcnancan","papapaappapa"]
function thesisFinal(){
var
randomThesis=Math.floor(Math.random()*(thesis.length));
document.getElementById('thesisget').innerHTML=thesis[randomThesis];
}
function removeThesis(){
}
</script>
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new web page with name "thesis.html" is created, which contains following code.
thesis.html :
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<button class="wew" onclick="thesisFinal()"><i class="fa fa-play-circle"> Start</i></button></div>
<button class="wew" onclick="removeThesis()"><i class="fa fa-play-circle"> Remove</i></button></div>
<p id="thesisget">Click to generate</p>
</div>
</div>
<script>
//array
var thesis=["car","waybipt","wew","aioweaio","awuiegauega","aiowehauiehauiw","aopwiheioaheauiowhe","cajicnajcnancan","papapaappapa"]
//display random element from the array
function thesisFinal(){
var randomThesis=Math.floor(Math.random()*(thesis.length));
document.getElementById('thesisget').innerHTML=thesis[randomThesis];
}
//function to remove array element
function removeThesis(){
//generate random number to delete array element
var removeThesis=Math.floor(Math.random()*(thesis.length));
//display element
document.getElementById('thesisget').innerHTML=thesis[removeThesis];
//remove array element from the array
thesis.splice(removeThesis,1);
}
</script>
</body>
</html>
======================================================
Output : Open web page thesis.html in the browser and will get the screen as shown below
Screen 1 :thesis.html
Screen 2:Screen when start button is clicked
Screen 3:Screen when remove button is clicked
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Get Answers For Free
Most questions answered within 1 hours.