Basic function challenge
Introduction
Today I took on the challenge of writing a simple code utilizing functions in Javascript. This challenge was from my Udemy course.
Challenge Description
Challenge 1: Describe a Country
This challenge required me to list the name, population, and capital city of 2 different countries.
My Approach
After watching the video on functions I was really confused as to how they worked and their use in Js. I headed over to Chatgtp and asked for 6 very basic challenges. When I got stuck, I asked for a breakdown. It would usually provide me with a skeleton of how the code should look. I would stumble my way through with help from Chat and I still feel lost and confused. As for this challenge, I couldn’t get it to work until I realized I wasn’t placing a quotation around each parameter. I still get tripped up with basic syntax issues even at this stage of my learning.
My Code
function describeCountry(country, population, capitalCity) {
return `${country} has ${population} million people and its capital city is ${capitalCity}.`
}
describeCountry();
const description1 = describeCountry('Poland', '6', 'Warsaw');
const description2 = describeCountry('Russia', '240', 'Moscow');
console.log(description2);
Lessons Learned
- Don’t forget quotation marks around strings!
Next Steps
I plan on asking Chatgtp to give me more very basic challenges in the hope that functions start to feel a bit more familiar to me.