<commit_before>'use strict';

// store all users
var allUsers = [];

// create constructor for new user
function User(name, drink) {
  this.name = name;
  this.drink = 'images/' + drink;
  this.score = 0;
}

// Gather User Data //
// add event listener to the user submission form
var userForm = document.getElementById('user-form');
userForm.addEventListener('submit', generateUser);

// generate a new user from the event handler
function generateUser(event) {
  event.preventDefault();
  var userName = event.target.username.value;
  var radios = event.target.avatar;
  for (var i = 0; i < radios.length; i++) {
    if (radios[i].checked === true) {
      var drinkSelected = (radios[i].value);
    }
  }
  var userDrink = drinkSelected;

  var newUser = new User(userName, userDrink);
  allUsers.push(newUser);
  event.target.username.value = '';

  // Store All User Data to localStorage
  function storeData() {
    var userDataJSON = JSON.stringify(allUsers);
    localStorage.setItem('userData', userDataJSON);
  }
  storeData();
  resetIcon();
}

// Start Game and Retrieve Data
var startButton = document.getElementById('play');
startButton.addEventListener('click', loadGame);

function loadGame(event) {
  event.preventDefault();
  window.location.replace('category.html');
}

<commit_msg>add check to overwrite upon username input conflict<commit_after>'use strict';

// store all users
var allUsers = [];

// create constructor for new user
function User(name, drink) {
  this.name = name;
  this.drink = 'images/' + drink;
  this.score = 0;
}

// Store All User Data to localStorage
function loadData(load) {
  if (localStorage['userData']) {
  var userDataLSString = localStorage['userData'];
  load = JSON.parse(userDataLSString);
  } else {
    console.log('loadData() :: no userData key found in localStorage object');
  }
}

function storeData(store) {
  var userDataJSON = JSON.stringify(allUsers);
  localStorage.setItem(store, userDataJSON);
}

// Gather User Data //
// add event listener to the user submission form
var userForm = document.getElementById('user-form');
userForm.addEventListener('submit', generateUser);

// generate a new user from the event handler
function generateUser(event) {
  console.log('generateUser() :: ***fired***')
  event.preventDefault();
  loadData(allUsers);
  var userName = event.target.username.value;
  var radios = event.target.avatar;

  for (var i = 0; i < radios.length; i++) {
    if (radios[i].checked === true) {
      var drinkSelected = (radios[i].value);
    }
  }
  var userDrink = drinkSelected;

  // check to see if user already exists, overwrite if so
  var newUser = new User(userName, userDrink);
  var userNameConflict = false;
  for (var i = 0; i < allUsers.length; i++) {
    if (allUsers[i].name === newUser.name) {
      allUsers[i] = newUser;
      userNameConflict = true;
      console.log('generateUser() :: name already exists; overwriting user object at index ' + i + ' of allUsers'); // consider giving user-visible feedback
      break;
    }
  }

  if (userNameConflict = false) {
      allUsers.push(newUser);
  }

  event.target.username.value = '';

  storeData('userData');
  resetIcon();
}

// Start Game and Retrieve Data
var startButton = document.getElementById('play');
startButton.addEventListener('click', loadGame);

function loadGame(event) {
  event.preventDefault();
  window.location.replace('category.html');
}


{'fraction_non_alphanumeric': 0.13380075956763074, 'fraction_numerical': 0.001460706982179375, 'mean_word_length': 3.9124820659971307, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '385451', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1021, 'n_words': 289}