Skip to content

Instantly share code, notes, and snippets.

@palumbo
Created August 27, 2022 18:10
Show Gist options
  • Save palumbo/ced4b8a116ddd82635254837b70fdc4d to your computer and use it in GitHub Desktop.
Save palumbo/ced4b8a116ddd82635254837b70fdc4d to your computer and use it in GitHub Desktop.
Google Apps Script that will take a value from a user and compare it to values stored in an array.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var nameArray = ["Joseph", "Elizabeth", "Roman", "Sophia"];
// GET VALUE FROM USER
let valueFromUser = Browser.inputBox("Who are you looking for?");
Logger.log(valueFromUser);
var answerCell = sheet.getRange("A1");
Logger.log(nameArray);
Logger.log(nameArray.indexOf(valueFromUser));
if (nameArray.indexOf(valueFromUser) >= 0) {
answerCell.setValue("The name is in the array");
} else {
answerCell.setValue("That name is NOT in the array");
answerCell.setBackground('red');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment