Created
August 27, 2022 18:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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