In: Computer Science
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to display "how's it going?" // from the variable myValue in the console // 5) Declare a variable named myOtherValue // Assign myOtherValue the value of "Ok?" // Use the concat() method on the variable myValue // to concatenate myValue and myOtherValue // Specify a new line as the first parameter of concat() // Print the result to the console // 6) Declare a variable named myRandom // Assign myRandom a non-rounded value between 0 and 1 using Math.random() // Print the result to the console // 7) Now assign a random value between 1 and 10 to myRandom // Use Math.floor() and Math.random() to accomplish this // Print the result to the console // 8) Print the length of the variable myValue to the console // 9) Set the contents of the variable myValue to all lowercase // Find the method to do this on your own // Print the variable to the console to show it now holds all lowercase // 10) **Solving a problem! // Declare a variable named myName and assign it your first name // Utilize the length property, Math.floor(), Math.random() and charAt() // methods to write a line of code that will randomly display a character // from your firstname in the console... refer to the examples of each // method at w3schools.com and MDN Web Docs
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new web page with name "Assignment03.html" is created, which contains following code.
Assignment03.html :
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>Assignment 03</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- <Script> is used for javascript -->
<script>
/* Assignment 03:
Complete this javascript */
// 1) Declare a variable named myValue
// Assign myValue the value of "Hello, how's it going?"
// Print the value of myValue to the console
var myValue="Hello, how's it going?";
console.log("1.myValue : "+myValue);
// 2) Use the charAt() method to display the letter t
// from the variable myValue in the console
console.log("charAt: "+myValue.charAt(14));
// 3) Use the indexOf() method to display the position of "going"
// from the variable myValue in the console
console.log("indexOf: "+myValue.indexOf("going"));
// 4) Use the slice() method to display "how's it going?"
// from the variable myValue in the console
console.log("slice : "+myValue.slice(7,22));
// 5) Declare a variable named myOtherValue
// Assign myOtherValue the value of "Ok?"
// Use the concat() method on the variable myValue
// to concatenate myValue and myOtherValue
// Specify a new line as the first parameter of concat()
// Print the result to the console
var myOtherValue="Ok?";
console.log("concat() :"+myValue.concat("\n",myOtherValue));
// 6) Declare a variable named myRandom
// Assign myRandom a non-rounded value between 0 and 1 using Math.random()
// Print the result to the console
var myRandom=Math.random();
console.log("myRandom (0-1) : "+myRandom);
// 7) Now assign a random value between 1 and 10 to myRandom
// Use Math.floor() and Math.random() to accomplish this
// Print the result to the console
myRandom=Math.floor(Math.random() * 11);
console.log("myRandom (0-10) : "+myRandom);
// 8) Print the length of the variable myValue to the console
console.log("length : "+myValue.length);
// 9) Set the contents of the variable myValue to all lowercase
// Find the method to do this on your own
// Print the variable to the console to show it now holds all lowercase
console.log("Lower Case : "+myValue.toLowerCase());
// 10) **Solving a problem!
// Declare a variable named myName and assign it your first name
// Utilize the length property, Math.floor(), Math.random() and charAt()
// methods to write a line of code that will randomly display a character
// from your firstname in the console... refer to the examples of each
// method at w3schools.com and MDN Web Docs
var myName="Virat";
console.log(myName.charAt(Math.floor(Math.random()*myName.length)));
</script>
</body>
</html>
======================================================
Output : Open web page Assignment03.html in the browser and will get the screen as shown below
Screen 1 :Assignment03.html
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.