diff --git a/Q1.js b/Q1.js new file mode 100644 index 0000000..79d90e8 --- /dev/null +++ b/Q1.js @@ -0,0 +1,4 @@ +// Q-1: Write a console.log statement saying "Hello World!" for each language that you know. +console.log('Hello World!'); //English language +console.log('سلام دنیا'); // Persian Language +console.log('ہیلو دنیا') // Urdu Language diff --git a/Q10.js b/Q10.js new file mode 100644 index 0000000..5bfd02c --- /dev/null +++ b/Q10.js @@ -0,0 +1,6 @@ +// I’ve declared a multidimensional array (an array inside an array) -- see below. Add a console.log statement accessing this item. +const grid = [[0, 1], [1, 1], [2, 1], [3, 1]]; +// How can I access the third item’s second element? i.e. [2, 1] is the third element, and I want to access 1. +const item = grid[2][1]; +console.log(grid.length); +console.log(item); diff --git a/Q11.js b/Q11.js new file mode 100644 index 0000000..ec8f36a --- /dev/null +++ b/Q11.js @@ -0,0 +1,4 @@ +// Q-11: If I have a variable counter, and I want to increment it by 2, what are three ways I can do this? Add three console.log statements with the three different ways. +let counter = 0; +counter = counter + 1; +console.log(++counter); diff --git a/Q12.js b/Q12.js new file mode 100644 index 0000000..52cecc5 --- /dev/null +++ b/Q12.js @@ -0,0 +1,10 @@ +//Q-12: Here’s a profile about a cat for adoption. Create variables to hold information about this cat as shown on the profile. For example: +const name = 'Prince'; +const bestFriend = 'Thomas'; +const adoptBoth = 'Both'; +const breed = 'Domestic Shorthair'; +const color = 'Orange or Red Tabby'; +const age = '1 year old, Young'; +let sex = 'Male'; +let petId = ''; +let hair = 'Short'; diff --git a/Q13.js b/Q13.js new file mode 100644 index 0000000..254e424 --- /dev/null +++ b/Q13.js @@ -0,0 +1,4 @@ +//Q-13: Create two variables -- one to hold the names of the kittens and one to hold the names of the adult cats. Make sure to choose an appropriate data type to hold this information! + +let nameAdult = 'Mezzo','Sabrina','Josie'; +let nameKitten = 'Kyle Meowry','Luna','Obi','Charlie','Raspberries'; diff --git a/Q2.js b/Q2.js new file mode 100644 index 0000000..4f8d01c --- /dev/null +++ b/Q2.js @@ -0,0 +1,6 @@ +// Q-2: Consider the following code: + +console.log('I'm awesome'); + +// The problem is in the wronge use of SINGLE QOUTE in I'm. To solve this problem we will have to replace the outer single qoutes to double quotes. +// w3school "You can use quotes inside a string, as long as they don't match the quotes surrounding the string:" diff --git a/Q3.js b/Q3.js new file mode 100644 index 0000000..18b9777 --- /dev/null +++ b/Q3.js @@ -0,0 +1,9 @@ +// Declare a variable age and initialize it with an integer, using these exact steps: + +// ANSWER +let age; // declare variable +console.log('The value of age will be: twentyFive'); // Explain the value of age +console.log(age); // logged the value of age +age = 25; // initialized variable age with an integer +console.log('The value of age will be: twentyFive'); // add a console.log statement that explains what you think the value of age is. +console.log(age); // Add a console.log statement that logs the value of age. diff --git a/Q4.js b/Q4.js new file mode 100644 index 0000000..1fd566c --- /dev/null +++ b/Q4.js @@ -0,0 +1,11 @@ +// Q-4: Declare a variable name and assign a string to it. + +// ANSWERS + +// Write a console.log statement in which you explain in words what you think the value of the string is. +let string = 'This is my string'; +console.log('The value of my string will be: thisIsMyString'); +console.log(string); +string = 'New string to variable name'; +console.log('The new value of my string is: newStringToVariableName'); +console.log(string); diff --git a/Q5.js b/Q5.js new file mode 100644 index 0000000..4ce7051 --- /dev/null +++ b/Q5.js @@ -0,0 +1,16 @@ +// Q-5: How do you round the number 7.25, to the nearest integer (i.e., whole number)? + +//ANSWER + +//Declare a variable number and assign the number 7.25 to it. +let number = 7.25; +console.log(number); +// Declare another variable roundedNumber that has the value of number but rounded to the nearest integer. +var roundedNumber = Math.round(7.25); +console.log(+ roundedNumber); + +// So now we have number and roundedNumber find a way to compare the two values and store the highest of the two in a new variable. Console.log the highest value. +console.log(7.25 > 7); + +let highest = 7.25; +console.log(highest); diff --git a/Q6.js b/Q6.js new file mode 100644 index 0000000..f88ad69 --- /dev/null +++ b/Q6.js @@ -0,0 +1,14 @@ +// Q-6 ARRAYS +// Declare an empty array. Make sure that the name you choose indicates 'plurality', because an array is capable of containing more than one element. +const friendNames = []; +//Write a console.log statement that explains in words what you think the value of the array is. +console.log('The Value of the Array is :','Empty'); +// console.log your array +console.log(friendNames); +//Create an array that has your favorite animals inside (see if you can find a good name that exactly describes what this variable will hold). +const favoriteAnimales = ['Lion','Owl','Raccoon']; +//Log your array. +console.log(favoriteAnimales); +// Add a statement that adds Syeda’s favorite animal ('kitten') to the existing array. Log your new array +favoriteAnimales.push('Kitten'); +console.log(favoriteAnimales); diff --git a/Q7.js b/Q7.js new file mode 100644 index 0000000..3421624 --- /dev/null +++ b/Q7.js @@ -0,0 +1,6 @@ +//Q-7: More strings: Let's consider the following string: let myString = "this is a test". +// Add the string to your file and console.log it. +let myString = 'this is a test'; +console.log(myString); +// Find a way to get the length of myString.console.log the length of myString. +console.log(myString.length); diff --git a/Q8.js b/Q8.js new file mode 100644 index 0000000..561405f --- /dev/null +++ b/Q8.js @@ -0,0 +1,5 @@ +// If x equals 7, and the only other statement is x = x % 3, what would be the new value of x? +console.log(7%3); // the new value = 1 +//Add at least 3 console.log statements in which you show that you understand what % does. +console.log(10%5); +console.log(13%2); diff --git a/Q9.js b/Q9.js new file mode 100644 index 0000000..c7d324d --- /dev/null +++ b/Q9.js @@ -0,0 +1,13 @@ +// Q-9: Write a program to answer the following questions: + +//ANSWERS +// Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer. +const favoritesPlacesAndNumbers = ['India','17','Tajikistan','100']; +console.log(favoritesPlacesAndNumbers); +// Can you compare infinities? +console.log('could not answer this question?'); +// Does 6/0 === 10/0? How can you test this? +let x = 6/0; +let y = 10/0; +console.log(6/0 === 10/0); +// Add console.log statements to the above program in which you show that you understand the concepts (just like you've done in the above assignments).