JAVASCRIPT 13 ARRAY 04 SPLIT STRING TO ARRAY - RETURN VALUE FROM ARRAY OBJECTIVE
ID: 3598347 • Letter: J
Question
JAVASCRIPT 13 ARRAY 04
SPLIT STRING TO ARRAY - RETURN VALUE FROM ARRAY
OBJECTIVE
Practice creating and using arrays.
In E-BOOK SEARCH FOR AND READ
split <== This is what this assignment is about. Search for this and read carefully and completely.
delimiter
arrays
get value from array
do not change parameter values
parameter <== This has an important reminder about never changing parameter values
return value from delimited data <== This has a full example for you to study. READ THIS!
NOTICE
These instructions are deliberately brief. The intent here is to allow you to demonstrate what problem solving and programming skills you have mastered.
You can do this in 2 or 3 lines of code. No loop is used here.
CREATE javascript 13 array 04.js (there is no HTML page)
DO THIS
1. Create javascript 13 array 04.js with a general function: animal() with three parameters:
delimiter
data (this is a delimited list of animals)
arrayIndex
All three parameters must be used in your function. Did you search for and read in e-book: do not change parameter values
2. The function will do this:
a. Split data into an array.
b. Return the array value at position arrayIndex.
TIPS
Do not give the parameters values. Use all three parameters.
If you want to test: After the end of your function, after }; use alert(animal(a,b,c)) where a,b and c are legitimate parameter values. If you do this:
The first two values are strings so you need quotes. The 3rd is a number.
Click GO to test.
Remove this alert() after you test before you GRADE.
A. INSTRUCTIONSSPLIT STRING TO ARRAY - RETURN VALUE FROM ARRAY
OBJECTIVE
Practice creating and using arrays.
In E-BOOK SEARCH FOR AND READ
split <== This is what this assignment is about. Search for this and read carefully and completely.
delimiter
arrays
get value from array
do not change parameter values
parameter <== This has an important reminder about never changing parameter values
return value from delimited data <== This has a full example for you to study. READ THIS!
NOTICE
These instructions are deliberately brief. The intent here is to allow you to demonstrate what problem solving and programming skills you have mastered.
You can do this in 2 or 3 lines of code. No loop is used here.
CREATE javascript 13 array 04.js (there is no HTML page)
DO THIS
1. Create javascript 13 array 04.js with a general function: animal() with three parameters:
delimiter
data (this is a delimited list of animals)
arrayIndex
All three parameters must be used in your function. Did you search for and read in e-book: do not change parameter values
2. The function will do this:
a. Split data into an array.
b. Return the array value at position arrayIndex.
TIPS
Do not give the parameters values. Use all three parameters.
If you want to test: After the end of your function, after }; use alert(animal(a,b,c)) where a,b and c are legitimate parameter values. If you do this:
The first two values are strings so you need quotes. The 3rd is a number.
Click GO to test.
Remove this alert() after you test before you GRADE.
Explanation / Answer
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls a function which performs array based index separation and return specified index string</p>
<p id="demo"></p>
<script>
function animals(a,b,c) {
var res = str.split(" ");
return res[c];
}
var single = "cat dog parrot ant";
var arr = {};
document.getElementById("demo").innerHTML = animals("",single,2);
</script>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.