Advertisement
Bubbs

list.js

Jan 10th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let list = [];
  2.  
  3. function highlight(){
  4.     alert('Your word is already in the list..');
  5. }
  6.  
  7.  
  8. function add_to_list(list){
  9.     let Selection = document.getElementById('selection').value;
  10.     for(let i = 0; i < list.length; i++){
  11.         for(x in list[i]){
  12.             if(x === ''){
  13.                 alert('Field is empty');
  14.             }
  15.             if(x === Selection){
  16.                 highlight();
  17.             }
  18.             if(x != Selection){
  19.                 list.push(x);
  20.             }
  21.         }
  22.     }
  23. }
  24.  
  25. function remove_from_list(list){
  26.     let Selection = document.getElementById('selection').value;
  27.     for(let i = 0; i < list.length; i++){
  28.         for(x in list[i] == Selection){
  29.             list.pop(x);
  30.         }
  31.     }
  32. }
  33.  
  34. function view(list){
  35.     console.log(list);
  36. }
  37.  
  38.  
  39. view.onclick = function(){
  40.     view(list);
  41. }
  42.  
  43. push.onclick = function(){
  44.     add_to_list(list);
  45. }
  46.  
  47. pop.onclick = function(){
  48.     remove_from_list(list);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement