Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

//1.Write a console.log statement saying "Hello World!" for each language that you know.
console.log('Hello World!'); // English
console.log('Merhaba Dunya!'); //Turkish
console.log('Marhaba Dunia!') //Zazaki


//2.Consider the following code:
console.log('I\'m awesome');

//3.Declare a variable age and initialize it with an integer, using these exact steps:
let x;
console.log('the value of age will be: 30');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you ran your program, do you understand why x isn't 30 when you first declared it on line 12?

console.log(x);
x=30;
console.log('the value of age will be: 30');
console.log(x);

//4.Declare a variable name and assign a string to it.

let y ='butterfly';
console.log('the value of my string will be:bird');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you made a typo, but the value of y isn't bird here.

console.log(y);
y='bird';
console.log('the value of my string will be:bird');
console.log(y);


//5.How do you round the number 7.25, to the nearest integer (i.e., whole number)?

let number=7.25;
console.log(number);// prints 7.25

let roundedNumber=Math.round(number);
console.log(number); // prints 7

if(roundedNumber < number){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work here, but make sure you declare your variable result with the let keyword, i.e. let result;. Otherwise, it'll automatically become a global variable (https://www.w3schools.com/js/js_scope.asp)

result=roundedNumber;
}
else{
result=number;
}
console.log(result);


//6.Arrays

let colors=[];
console.log('the value of my array is: blue, yellow, green, black');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget to add some colors to your array?

console.log(colors);

let myFavoriteAnimals=['rabbit', 'cat', 'bird', 'dog'];
console.log(myFavoriteAnimals);
myFavoriteAnimals.push('kitten');
console.log(myFavoriteAnimals);


//7.More strings: Let's consider the following string: let myString = "this is a test".

let myString = "this is a test";
console.log(myString);
console.log(myString.length);


//8.If x equals 7, and the only other statement is x = x % 3, what would be the new value of x?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job with the examples here!


x = 7;
x = x % 3;
console.log(x);

y=15;
y=y % 5;
console.log('remainer is 0 from 15 /5');

z=20;
z=z % 6;
console.log('remainer is 2 from 20 /6');



//9.Write a program to answer the following questions:

let numberString=[1,2,3,'hamza', 'yunus',true,];
console.log(numberString);
console.log('we can store multiple types in an array with their special signs ex: string must be between \'\' or \"\".')

console.log(6/0===10/0);
console.log('3 equals compare two values if they are same values and types.')



//10.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]];
console.log(grid[2][1]);



//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;
console.log('first method');
console.log(counter + 2);


counter=+2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counter = +2 actually assigns the value of the counter to 2. The third method would be to write this out twice:
counter++;
counter++;

console.log('Second method');
console.log(counter);


counter+=2;
console.log('third method');


//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 breed ='Domestik Shorthair';
const color ='Orange or Red Tabby';
const age = '1 year old';
const sex = 'Male';
const hair ='Short';
const info=['Neutered', 'Good with Kids', 'Shots Up to Date', 'Good with Cats'];
const aboutStory=['facebook', 'twitter', 'pinterest', 'email'];
const date='july 28,2018';
console.log(name+' is '+info+'his best friend is '+bestFriend+' He is '+age+' and has '+ hair+ 'hair');


//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 kittens=['Kyle Meowry', 'Luna', 'Obi','Charlie', 'Raspberries'];
let adults=['Mezzo', 'Sabrina', 'josie'];