Quickly Build a Daily Random Motivational Quote Website

Learn how to create a daily random motivational quote website using Google Sheets and Apps Script. This tutorial walks you through the process of embedding quotes and deploying a web app to display a new quote each day.

we're going to build a website where we create a daily random motivational quote. I have this sheet here of 366 quotes and we want to get this Google sheet out onto a website and every time we refresh that website or go to that maybe once a day, we're going to get a new quote, a random quote. So I'm going to show you how to do this. We haven't had any Apps Script written yet. I'll write that, but I have the embed code here already done. What we need here is a URL, which we'll get when we deploy a web app that will grab the data that we want. Which in this case will be a quote, and then it will show it in this quote ID, which is just an H1 style here, but let's do this first. Let's create the code for this. Our code, our, our code will grab a random one from A1 to A36.

So first we need to get that. So we'll get quotes equals spreadsheet app dot get active spreadsheet . Get sheet by name, and I think it's all quotes, all capitalized, quotes, and we need a variable quotes array equals quotes dot get range , and it's going to be a 1, a 366, that's 366 quotes, and we'll get the values . Okay, so once we have that, we need a randomized thing from here. So let's do this. I'm going to show you a really cool trick which is just using ChatGPT to finish this. But what we want to do is get a random item from this array. So we'll take this. I'll copy it and go to ChatGPT and ask.

This is something you can do if you want to quickly get sort of some kind of little algorithm, a little part of your Apps Script that you don't necessarily know how to do. So, finish this getting random item from array. And with that spreadsheet app there, it looks, it's going to look like it's Apps Script , so they'll know that it's Apps Script . And we just need a little bit of JavaScript here. It should be something like math. floor. We'll see here what it does. Or like math dot random. Forgot what it was. Random, math dot floor, math dot random times quote array dot length. Cool. And then we're going to select that item. Perfect. So, let's just grab this out of here. And put that there. We'll actually delete that line. Okay, so this is random index , and then we need that next part. Variable. Random quote.

Okay, so where are we going to put this random quote? Actually I don't know if we need this zero at the end. We'll see if we do. Maybe we do. Let's just put it there and let's test this. Logger dot log random quote. What I want to do is instead of function do get, which we're going to need for our deployment, we're going to get a random quote. I'm going to call that. And once it's saved, let's run it and look at our log and see if we have an error get random queue, tempted to execute. Oh, because it's a different name now. Okay. We'll review our permissions. We just have to do this the very first time we create this or run it here and we've got one. Great. Let's run it again. See if we get another one, different one. Yeah, great. We're getting it. Awesome. So now we have this random quote coming and we can even, we can actually

just say return random quote there. So now we can call this function somewhere else. So we want to function , do get, and we're gonna need this random quote to be the return of this do get, which is. Variable quote equals get, get random quote, we're just going to get that, but we can't return just the text. What we need to do is it's going to be content service dot create text output, and we want random quote in there. Okay, so now our deployment, it's going to be new deployment. We will select type will be web app execute as me and anyone deploy. Now we're going to get a URL here. We're going to use that URL in our HTML.

So again, I have it already copied here, this embed, but let's go make a website. I'm going to use card, C A R D. It's pretty simple to create a blank canvas here and write today's quote in a text. And then right under it, we will add an embed. And all we have to do is grab this embed, but actually we need to get, let's manage that appointment again, grab that URL. There it is. Web app and put it inside of our URL here. So we'll replace that URL. with this. Save it. And now this is again, just taking an H1 ID quote with font size 50 color white. It's replacing that with a little text here, which is going to be the responsive here. Let's look at this.

Actually, if we go to an incognito tab there is a weird thing where if you're running a Google Google script in a non incognito tab, it won't work, but incognito, it will. There we go. And every time we refresh this, she'd give us another quote. Great. Perfect. So that's how we know it is working. Get this embed into our site. We are going to, we don't need a label in line. Yes. And just paste it in our quote code. Sorry, here done. Is he's going to be white. So let's make sure this background is a little bit darker. Maybe a dark, dark green. And today's quote is white as well. Done. Okay, we're gonna save this random quote, quote of the day, publish to a card URL, random quote. Let's see if that's available.

It'll check for the subdomain . Perfect. It's available. Randomquote. card. co, and we can visit the site and see if it's working. And if there's any issues, we will see. To err is human. To admit it, superhuman. Perfect. So now at randomquote. card. co, any time we refresh this we're going to have a new random quote. So we can do this every day. We can have this URL saved to our bookmarklet tab, maybe. Or, open this every time we open a new tab, it, we can set it to go to random quote dot card dot co, and we'll get a random quote every time. I did make these quotes sort of inspirational and motivational, but also some of them, or most of them have to do with spreadsheets, so I took a random assortment. If you're looking for this sheet of quotes and this code, Become a BetterSheets member today.

If you're watching this on BetterSheets. co, down below is the link to the sheet. Get every sheet here on BetterSheets.