-
Notifications
You must be signed in to change notification settings - Fork 10
week6 assignment #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
inanfatih
wants to merge
1
commit into
hackyourfuturecanada:master
Choose a base branch
from
inanfatih:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| // Due Date: Sunday, August 25, 2019 at 6:00 p.m. | ||
|
|
||
| // Complete the following assignment on JavaScript 1 and push your file to GitHub for reviewing by the instructor. | ||
|
|
||
| // For all the following exercises create one .js file. Separate the questions using comments. | ||
|
|
||
| // Write a console.log statement saying "Hello World!" for each language that you know. | ||
| // For example: | ||
|
|
||
| // Halo, dunia! // Indonesian | ||
|
|
||
| // Ciao, mondo! // Italian | ||
|
|
||
| // Hola, mundo! // Spanish | ||
|
|
||
| console.log('Merhaba Dunya'); | ||
| console.log('Hello World'); | ||
| console.log('Hola, mundo!'); | ||
|
|
||
| // Consider the following code: | ||
| // console.log('I'm awesome'); | ||
| // Copy the code in your .js file and run it. You will see that you will get a SyntaxError. Find a solution for this error. Hint: read the error message carefully, it also gives an indication of where the problem is. | ||
|
|
||
| console.log("I'm awesome"); | ||
|
|
||
| // Declare a variable age and initialize it with an integer, using these exact steps: | ||
| let age; | ||
|
|
||
| // First, declare your variable age (do not initialize it yet). | ||
| // Add a console.log statement that explains in words what you think the value of age is | ||
|
|
||
| console.log('age is undefined'); | ||
|
|
||
| // Add a console.log statement that logs the value of age. | ||
| console.log(age); | ||
|
|
||
| // Now initialize your variable age with an integer. | ||
| age = 33; | ||
| // Next, add a console.log statement that explains what you think the value of age is. | ||
| console.log('it is 33'); | ||
| // Add a console.log statement that logs the value of age. | ||
| console.log(age); | ||
| // Example steps for question 3: | ||
| // // TODO -> here you declare your variable | ||
| // console.log('the value of age will be: whateverYouThinkItWillLog'); | ||
| // // TODO -> log the actual value of age | ||
| // // TODO -> here you initialize your variable | ||
| // console.log('the value of age will be: whateverYouThinkItWillLog'); | ||
| // // TODO -> log value of age again | ||
|
|
||
| // Declare a variable name and assign a string to it. | ||
| let aString = 'world'; | ||
| // Write a console.log statement in which you explain in words what you think the value of the string is. | ||
| console.log('it is world'); | ||
| // Now console.log the variable name. | ||
| console.log(aString); | ||
| // Now assign a new string to the variable name. | ||
| aString = 'Jupiter'; | ||
| // Just like what you did before write a console.log statement that explains in words what you think will be logged to the console. | ||
| console.log('it is Jupiter'); | ||
| // Now console.log name again. | ||
| console.log(aString); | ||
| // Example steps for question 4: | ||
|
|
||
| // // TODO -> here you declare AND assign your string | ||
| // console.log('the value of my string will be: whateverYouThinkItWillLog'); | ||
| // // TODO -> log the actual value of the string to the console | ||
| // // TODO -> assign a new value to your variable name | ||
| // console.log('the value of my string will be: whateverYouThinkItWillLog'); | ||
| // // TODO -> log the actual value of the string to the console | ||
|
|
||
| // How do you round the number 7.25, to the nearest integer (i.e., whole number)? | ||
| Math.round(7.25); | ||
| console.log(Math.round(7.25)); | ||
| // Declare a variable number and assign the number 7.25 to it. | ||
| aNumber = 7.25; | ||
| // console.log number. | ||
| console.log(aNumber); | ||
| // Declare another variable roundedNumber that has the value of number but rounded to the nearest integer. | ||
| roundedNumber = Math.round(aNumber); | ||
| // console.log number. | ||
| 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. | ||
|
|
||
| let highestNumber; | ||
| if (aNumber > roundedNumber) { | ||
| highestNumber = aNumber; | ||
| } else { | ||
| highestNumber = roundedNumber; | ||
| } | ||
|
|
||
| // console.log the highest value. | ||
| console.log(highestNumber); | ||
| // 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 arr = []; | ||
| // Write a console.log statement that explains in words what you think the value of the array is. | ||
| console.log('arr does not have any value'); | ||
| // console.log your array. | ||
| console.log(arr); | ||
| // 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 myFavouriteAnimals = ['cat', 'lion', 'bird', 'sheep', 'cow', 'donkey']; | ||
| // Log your array. | ||
| console.log(myFavouriteAnimals); | ||
|
|
||
| // Add a statement that adds Syeda’s favorite animal ('kitten') to the existing array. | ||
| myFavouriteAnimals.push('kitten'); | ||
|
|
||
| // Log your new array | ||
| console.log(myFavouriteAnimals); | ||
| // More strings: Let's consider the following string: let myString = "this is a test". | ||
| let myString = 'this is a test'; | ||
| // Add the string to your file and console.log it. | ||
| console.log(myString); | ||
| // Find a way to get the length of myString. | ||
| myString.length; | ||
| // console.log the length of myString. | ||
| console.log(myString.length); | ||
|
|
||
| // If x equals 7, and the only other statement is x = x % 3, what would be the new value of x? | ||
| let x = 7; | ||
| x = x % 3; | ||
| console.log(x); | ||
| // Add at least 3 console.log statements in which you show that you understand what % does. | ||
| console.log( | ||
| '% is used to show remainder of the first number when divided to the second' | ||
| ); | ||
| console.log('8%5 is equal to 3 ==> ' + (8 % 5)); | ||
| console.log('9%5 is equal to 4 ==> ' + (9 % 5)); | ||
| console.log('10%5 is equal to 0 ==> ' + (10 % 5)); | ||
| // Write a program to answer the following questions: | ||
|
|
||
| // Can you store multiple types in an array? Numbers and strings? Make an example that illustrates your answer. | ||
| console.log( | ||
| 'Yes I cam store multiple types in an array but it is not a good practice' | ||
| ); | ||
| const arrayWithMultipleTypes = [5, 'this array has both a string and a number']; | ||
| console.log(arrayWithMultipleTypes); | ||
| // Can you compare infinities? Does 6/0 === 10/0? How can you test this? | ||
| console.log( | ||
| 'I was thinking as if Infinitys are not comparable but according to the following test, they are comparable and Infinity = Infinity' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm glad you were able to test this! |
||
| ); | ||
|
|
||
| // 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). | ||
|
|
||
| if (6 / 0 === 10 / 0) { | ||
| console.log('infinities are comparable'); | ||
| } else { | ||
| ('infinities are not comparable'); | ||
| } | ||
| let a = 6 / 0; | ||
| let b = 10 / 0; | ||
| console.log(a); | ||
| console.log(b); | ||
| console.log(a === b); // this is returning true | ||
|
|
||
| // I’ve declared a multidimensional array (an array inside an array) -- see below. How can I access the third item’s second element? i.e. [2, 1] is the third element, and I want to access 1. Add a console.log statement accessing this item. | ||
| // const grid = [[0, 1], [1, 1], [2, 1], [3, 1]]; | ||
| const grid = [[0, 1], [1, 1], [2, 1], [3, 1]]; | ||
| console.log(grid[2][1]); | ||
|
|
||
| // 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; | ||
| // console.log(‘first method’); | ||
| let counter = 0; | ||
| counter += 2; | ||
| console.log('first method: ' + counter); | ||
| counter = counter + 2; | ||
| console.log('second method: ' + counter); | ||
| counter++; | ||
| counter++; | ||
| console.log('third method: ' + counter); | ||
|
|
||
| // 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 name = 'Prince'; | ||
| const bestFriend = 'Thomas'; | ||
| const breed = 'Domestic Shorthiair'; | ||
| const sex = 'male'; | ||
| const color = 'Orange or Red Tabby'; | ||
| const age = '1 year old, Young'; | ||
| const hair = 'short'; | ||
| const DOB = 'July 28, 2018'; | ||
| const info = [ | ||
| 'Neutered', | ||
| 'Good with Kids', | ||
| 'Shots up to date', | ||
| 'good with cats' | ||
| ]; | ||
|
|
||
| //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! | ||
|
|
||
| const kittenNames = ['Kyle', 'Luna', 'Obi', 'Raspberries', 'Charlie']; | ||
| const adultNames = ['Mezzo', 'Sabrina', 'Josie']; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good, but don't forget to use the
letorconstkeyword for variables.