Question
Fix the errors in this javascript file, You must have an output for each code. //JavaScript Methods //Java script strings// //Use the length property to
Fix the errors in this javascript file, You must have an output for each code.
//JavaScript Methods //Java script strings// //Use the length property to alert the length of txt. var txt = "Hello World!"; var x = txt.length; (x);
//Use escape characters to alert We are "Vikings". var txt = "We are \"Vikings\""; alert();
//Concatenate the two strings to alert "Hello World!". var str1 = "Hello "; str2 = "World!"; alert(str1+str2);
//Find the position of the character h in the string txt. var txt = "abcdefghijklm"; var pos = txt.indexOf("h"); alert(pos)
//Use the slice method to return the word "bananas". //method returns a shallow copy of a portion of an array into a new array object selected from begin to end var txt = "I can eat bananas all day"; var x = txt.slice(10, 17); (x)
//Remove the fourth character in a string var txt1 = "I can eat bananas all day"; var x1 = txt.slice(4); alert(00);
//Use the splice() method to remove //"Orange" and "Apple" from fruits. //Remove or add //Changes the original array var fruits = ["Banana", "Orange", "Apple", "Kiwi"]; fruits.splice(1, 2);//Remove the second element(#1) and third element(#2) alert(fruits);
//Remove, then print up to# //doesn't change the original array var animals = ['ant', 'camel', 'duck', 'elephant']; var one = animals.slice (1,2); //Remove the first two //then print up to #2 (one);
// String method to replace the word "Hello" with the word "Welcome". var txt = "Hello World"; txt = txt.replace("Hello", "Welcome"); (txt);
//Convert the value of txt to upper case. var txt = "Hello World"; var txt = txt.toUpperCase(); alert(txt);
//Convert the value of txt to lower case. var txt = "Hello World"; txt txt.toLowerCase(); alert(txt);
//Use the concat() method create a string that says "Hello World!". var str1 "Hello "; var str2 = "World!"; var result = str1.concat(str2); alert(result)
//Get the value "Volvo" from the cars array. var cars = ["Saab", "Volvo", "BMW"]; var x = cars[1]; alert();
//JavaScript array// //Change the first item of cars to "Ford". var cars = ["Volvo", "Jeep", "Mercedes"]; cars[900]= "Ford"; alert(cars);
//Alert the number of items in an array, using the correct Array method. var cars ["Volvo", "Jeep", "Mercedes"]; alert(cars.length);
//Array method to remove the last item of the fruits array. var fruits = ["Banana", "Orange", "Apple"]; fruits.pop(fruits); alert()
//Array method to remove the first item of the fruits array. var fruits = ["Banana", "Orange", "Apple"]; fruits.shift(); alert(fruits)
//Array method to add "Kiwi" to the fruits array. var fruits = ["Banana", "Orange", "Apple"]; fruits.push("Kiwi"); alert();
//Use the concat() method to concatenate girls and boys. var girls = ["Cecilie", "Lone"]; var boys = ["Emil", "Tobias", "Linus"]; var children = girls.concat(boys); (childrens);
// Array method to sort the fruits array alphabetically. var fruits = ["Banana", "Orange", "Apple", "Kiwi"]; fruits.sort(); alert(fruit);
//reverse var fruits = ["Banana", "Orange", "Apple", "Kiwi"]; fruits.reverse(); (fruits);
//JavaScript Dates// //Create a Date object and //alert the current date and time. var d = new Date(); alert();
// Date method to extract the year (four digits) out of a date object. var d = new Date(); (year = d.getFullYear());
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started