Define a function named firstLetterName. It should take a string name as a parameter and alert the message "The name <NAME> starts with the letter <FIRSTLETTEROFNAME>
HINT: to get a single character of a string, you can use bracket syntax like you used to access array elements
Define a function divisibleByTwo. It should take a single parameter number and determine whether the number input is an even or odd number. If it's even, the function should return true. If it's odd, the function should return false.
HINT: You'll need to use the % operator.
Define a function named largestNum. It should take an array arr as a parameter and loop through that array. The function should return the largest number in the array.
After defining all the functions, call each function at the bottom of the JavaScript file with the appropriate arguments.
#Learning how to use functions..
13 messages · Page 1 of 1 (latest)
This is what im supposed to do^^
let firstName = prompt("What is your first name?")
let firletter = firstname.charAt(0);
firstLetterName() {
alert("The name " + firstName + "beings with the letter " + firletter);
}```
this is what i have so far
You're close
Except that doesn't really define a function
A basic template for defining a function in javascript looks something like this ```js
function func_name(parameters) {
body of the function
}
function defines a function called func_name that takes in parameters as a parameter
So what you'd do is ```js
function firstLetterName(...) {
alert("The name " + firstName + "beings with the letter " + firletter);
}
ah thank you
I'll let you figure out what to put in the brackets
is it like this?
let firstName = prompt("What is your first name?")
let firletter = firstname.charAt(0);
function firstLetterName(firstName) {
alert("The name " + firstName + "begins with the letter " + firletter);
}
function divisibleByTwo() {
}
function largestNum() {
}
/* calling functions below */
firstLetterName();
divisibleByTwo();
largestNum();```