Closed ghost closed 3 years ago
Week 4 Step 6 ⬤⬤⬤⬤⬤⬤◯ | 🕐 Estimated completion: 5-20 minutes
Now that we've got a frontend that can only return one picture, let's take it to the next level and return FOUR pictures at the same time. To do this, let's edit our old twoCatz function.
twocatz-frontend
branchname1
, name2
, name3
, name4
) and returns four pictures in base64 with the parameters.twocatz/index.js
and test your result with PostmanTWOCATZ_ENDPOINT
secret since you are editing the same functionOpen up Postman again since we are testing an API.
⚠️ Make a GET request with the four name parameters. Do you get a JSON object containing name1
, name2
, name3
, and name4
attributes encoded in base64?
:bulb: Having trouble? Look back to old branches - these skills were all used before!
That's it for Week 4! Great job on finishing the course!
Week 4 Step 5 ⬤⬤⬤⬤⬤◯◯ | 🕐 Estimated completion: 5-20 minutes
Create the CataaS Website ~ meow
Demo: 🐱
Create a website that return a picture from the CatAAS API with the name of the cat being the input (each click should call the Cataas API)
✅ Task:
twocatz-frontend
branchcatzapp/index.html
with a text input (type="text"
) and a button (type="button"
) that calls the Javascript functiony1k3s()
intwocatz/index.js
img
object with idimage
incatzapp/index.html
y1k3s()
function that replaces theimg
div with a picture from the CataaS API containing input from the text boxcatzapp/index.html
andcatzapp/script.js
to thetwocatz-frontend
branchtwocatz-frontend
tomain
, but do not merge it🚧 Test your Work
Open up your LiveServer plugin and start your local server. To test your web app:
⚠️ When you enter "catzrule" into the textbox and click the button, is there a picture that appears with a cat and "catzrule" on it?
Creating an HTML template
In Visual Studio Code, you can create a html template containing the basic header tags by typing
!
+Tab
. This will create something like:Getting the Cat Pic
The
img
tag embeds an image, and it has attributes. We'll be usingsrc
.:question: How can I modify src to get the picture?
When the button is clicked, it will call `y1k3s()`, so we will add a line of code in the function. In HTML, the img tag looks like this: ```html ``` We can change the `src` value to a URL, or a file on a server. In our case, we'll change it to a URL to the Cat API. > :bulb: Recall that the endpoint is https://cataas.com/cat/says/[your_text] ```js document.getElementById("YOUR_IMAGE_ID").src = THE_ENDPOINT + THE_INPUT ```