Trying to avoid creating a node with existing coordinates, I implemented a check in my code. The check is supposed to determine if there are any nodes with the same coordinates already present. However, it seems that the check is not working as expected and I'm unable to locate the mistake.
The NodeX and NodeY ids correspond to input type number elements.
function create_node(){
var coordinates = [parseFloat(document.getElementById('NodeX').value), parseFloat(document.getElementById('NodeY').value)];
var coordinate_check = 0;
for (var item of node_coordinates){
if (item == coordinates){
coordinate_check = 1
}
}
if (document.getElementById('NodeX').value == ""){
console.log('Please enter X coordinates.')
}
else if (document.getElementById('NodeY').value == ""){
console.log('Please enter Y coordinates.')
}
else if (coordinate_check == 0){
if (nodes.length == 0){
nodes.push(1);
}
else{
nodes.push(1+nodes[nodes.length-1]);
}
node_coordinates[nodes.length-1] = coordinates;
node_loads[nodes.length-1] = [0, 0, 0];
restraints_names[nodes.length-1] = 'none';
restraints_dofs[nodes.length-1] = ['free','free','free'];
document.getElementById('nodeselect').innerHTML = update_nodelist();
}
else{
console.log('Node Exists!');
}
console.log(nodes);
console.log(node_coordinates);
};