What i'm trying to do is to display the name, number and socialmedia of my array at the click of the add Button. Then to remove that same name, number and social media at the same time and then when clicking to also search that name, number and social media. I would be okay just for you to help me with the add button. I don't understand what's wrong with my code. Thank you in advance
let addBtn = document.querySelector('#addBtn');
let removeBtn = document.querySelector('#removeBtn');
let searchBtn = document.querySelector("#searchBtn");
let contacts = [];
function Contact (name, number, socialmedia) {
this.name = name;
this.number = number;
this.socialmedia = socialmedia;
}
function createContacts(contactsLength) {
let arrName = ['', '', '']
let arrNumber = ['', '', '']
let arrMedia = ['', '', '']
for(let i=0; i<contactsLength; i++) {
let name = arrName[Math.floor(Math.random() * arrName.length)]
let number = arrNumber[Math.floor(Math.random() * arrNumber.length)]
let socialmedia = arrMedia[Math.floor(Math.random() * arrMedia.length)]
contacts.push(new Contact(name, number, socialmedia))
}
}
createContacts(10);
console.log(contacts);
addBtn.addEventListener('click', addContact)
function addContact() {
for(const list of contacts) {
({name, number, socialmedia} = list)
console.log(contact.name);
}
}
<!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>Document</title>
<link rel="stylesheet" href="css/style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body class="bg-dark">
<div class="container">
<h1 class="myh1 m-3 text-center">My Address Book</h1>
<div class="input-group">
<input id="myInput" type="text" class="form-control mb-3" placeholder="Type Contact" aria-label="Recipient's username with two button addons">
<button id="addBtn" class="btn btn-outline-info mb-3" type="button">Add</button>
<button id="removeBtn" class="btn btn-outline-info mb-3" type="button">Remove</button>
<button id="searchBtn" class="btn btn-outline-info mb-3" type="button">Search</button>
</div>
<table class="table table-info table-striped" id="myTable">
<thead>
<tr>
<th scope="col" id="name">Name</th>
<th scope="col" id="number">Number</th>
<th scope="col" id="socialmedia">Social Media</th>
</tr>
</thead>
<tbody>
</table>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<!-- JQuery + mio Javascript -->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
<script src="js/script4.js"></script>
</body>
</html>