Saturday, 9 August 2014

To learn it, you gotta 'do' it

Question 10/11

Write a do/while loop inside the function we've created for you, getToDaChoppa. The function should log a string of your choice to the console. do it now!

var getToDaChoppa = function(){
  // Write your do/while loop here!
  do{
      getToDaChoppa = false;
      console.log ("Please mention all above");
      }while(getToDaChoppa)
};

getToDaChoppa();

Tuesday, 5 August 2014

Tutorial 3/11
== Introduction to while loops ==
A fellow of infinite loops

Solve:
understand = true;

while(understand){
    console.log("I'm learning while loops!");
    //Change the value of 'understand' here!
    understand = false;
}

Tuesday, 15 July 2014

== Search Text for Your Name tutorial 5/7 ==
Okay! Last loopy step: add another for loop, this time inside the body of your if statement (between the if's {}s).
This loop will make sure each character of your name gets pushed to the final array. The if statement says: "If we find the first letter of the name, start the second for loop!" This loop says: "I'm going to add characters to the array until I hit the length of the user's name." So if your name is 11 letters long, your loop should add 11 characters to hits if it ever sees the first letter of myName in text.
For your second for loop, keep the following in mind:
First, you'll want to set your second loop's iterator to start at the first one, so it picks up where that one left off. If your first loop starts with
for(var i = 0; // rest of loop setup
your second should be something like
for(var j = i; // rest of loop setup
Second, think hard about when your loop should stop. Check the Hint if you get stuck!
Finally, in the body of your loop, have your program use the .push() method of hits. Just like strings and arrays have a .length method, arrays have a .push() method that adds the thing between parentheses to the end of the array. For example,
newArray = [];
newArray.push('hello');
newArray[0];   // equals 'hello'
 
Solve:
 
var text = "Hello world Keya how you doing Keya";
            
var myName ="Keya";
var hits = [];
for(var i=0; i<text.length; i++ )
{
    if (text[i]=== 'K')
    {
        for (var j=i; j< i+ myName.length; j++)
        {
            hits.push(text[j]);
            
        }
    }
} 
 
output: 8
 

Search Text for Your Name Tutorial 3#

Instructions:

Below your existing code, create a for loop that starts at 0, continues until it reaches the end of text, and increments by 1 each time. (This means it will check each character in the string.) There's no need to write anything between the {}s of your loop just yet.

Solve
var text = "Hello world Keya how you doing Keya";
           
var myName ="Keya";
var hits = [ ];
for(var i=0; i<text.length; i++ )
{}

 

Sunday, 13 July 2014

Loops and arrays II

Instructions:
  1. Create an array called names filled with 5 names.
  2. Write a for loop that prints "I know someone called " followed by names[i]. Make sure there's a space between "called" and the name!
  3. Run your code and the five sentences should print out.
Solve:

var name = ["a","b","c","d","e"];
for(var i=0; i<5; i++)
{
    console.log ("I know someone called "+name[i]);
    }

Output:
I know someone called  a

I know someone called b
I know someone called c
I know someone called d
I know someone called e

 

Sunday, 6 July 2014

== Array positions ==

Instructions:
Print out the fourth element of the array.
1. Start with figuring out how to express what the fourth element in the array is.
2. Then use console.log() to print things out!

Solve:
var junkData = ["Eddie Murphy", 49, "peanuts", 31];
console.log(junkData[3]);
 

Saturday, 28 June 2014

== Build "Rock, Paper, Scissors" ==
Tutorial 7#
What if choice1 is paper?
Now what if choice1 is "paper"? Given choice1 is "paper",
a. if choice2 === "rock", then "paper" wins.
b. if choice2 === "scissors", then "scissors" wins.

Instructions:
  1. Inside the compare() function under the existing code, write another else if statement where the condition is choice1 === "paper".
  2. Inside this else if statement, write an if / else statement. If choice2 === "rock", return "paper wins". Else, return "scissors wins".
Solve:
/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/
var compare = function(choice1, choice2)
{
if(choice1===choice2)
{
    return "The result is a tie!";
    }else if(choice1=== "rock"){
        {
            if(choice2 === "scissors")
        {
            return "rock wins";
            }
            else if(choice1=== "paper")
            {if(choice2 === "rock")
            {
                return "paper wins";
                }else return "scissors wins";
                }
           
            else return "paper wins";
            }
        }
};
compare("rock",1);

== Build "Rock, Paper, Scissors" ==
Tutorial 6#
What if choice1 is rock?
You're doing great! Now we consider the other scenarios. Let's break the problem down a little. What if choice1 is "rock"? Given choice1 is "rock",
a. if choice2 === "scissors", then "rock" wins.
b. if choice2 === "paper", then "paper" wins.

Problem:
Let's code our outline from above:
  1. Inside the compare() function under the existing code, write an else if statement where the condition is choice1 === "rock".
  2. Inside this else if statement, write an if / else statement. If choice2 === "scissors", return "rock wins". Else, return "paper wins".
Solve:
var compare = function(choice1, choice2)
{
if(choice1===choice2)
{
    return "The result is a tie!";
    }else if(choice1=== "rock"){
        {
            if(choice2 === "scissors")
        {
            return "rock wins";
            }
            else return "paper wins";
            }
        }
};
compare("rock",1);
== Build "Rock, Paper, Scissors" ==
Computer Choice: Part 2
We have computerChoice but it now equals a random number between 0 and 1. We need to somehow translate this random number into a random choice of rock, paper, or scissors. How do we do this?!
 Problem:
  1. If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
  2. If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
  3. If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors".
Solution:
var computerChoice= Math.random();
if(0.33<computerChoice < 0)
{
 computerChoice= "rock";
}
else if(0.64<computerChoice < 0.34)
{
 computerChoice= "paper";
}else(0.67<computerChoice < 1)
{
 computerChoice= "scissors";
}

Friday, 27 June 2014

== Build "Rock, Paper, Scissors" ==
Tutorial 3#
Instructions
  1. Under your previous code, declare a variable called computerChoice and make it equal to Math.random().
  2. Print out computerChoice so you can see how Math.random() works. This step isn't needed for the game - just useful for learning!
Code:
var computerChoice= Math.random();
console.log (computerChoice);
output:
 0.92242
=== Build "Rock, Paper, Scissors ===
Tutorial 2#
User Choice:
Instructions:
  1. Declare a variable called userChoice.
  2. Make the variable equal to the answer we get by asking the user "Do you choose rock, paper or scissors?"
Code:
var userChoice = prompt("Do you choose rock, paper or scissors?");

Thursday, 26 June 2014

Tutorial 12#
== Functions & if / else ==

An especially useful application of reusable code is if/else statements. These can be very wordy, and a pain to type repeatedly.
We are going to write a function that checks how many hours of sleep a night you're getting. Inside the function will be an if/else statement. We want the function to check many different numbers of hours to see whether a person is getting enough sleep.

Instructions:
  1. Write a function named sleepCheck that takes the parameter numHours
  2. Inside the function, write an if statement where if the number of hours of sleep is greater than or equal to 8, the computer will return "You're getting plenty of sleep! Maybe even too much!";.
  3. Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";
Then call the function with different hours of sleep
  1. Call the function with 10 hours of sleep, like this: sleepCheck(10);
  2. Call the function with 5 hours of sleep.
  3. Call the function with 8 hours of sleep.
Solve:
var sleepCheck= function(numHours)
{
     sleepCheck(8);
    if(numHours >= 8)
    {
        return console.log("You're getting plenty of sleep! Maybe even too much!");
        }
        else {
            return console.log("Get some more shut eye!");
            }
    }; 

codecademy: Introduction to Functions in JS Tutorial 10#
== Global and local Variable in JS ==
Let's talk about an important concept: scope. Scope can be global or local.

Variables defined outside a function are accessible anywhere once they have been declared. They are called global variables and their scope is global.
For example:
var globalVar = "hello";

var foo = function() {
    console.log(globalVar);  // prints "hello"
};
 
// The variable globalVar can be accessed anywhere, 
even inside the function foo.
 
Variables defined inside a function are local variables
They cannot be accessed outside of that function.
var bar = function() {
    var localVar = "howdy";
}

console.log(localVar);  // error 
 
The var keyword creates a new variable in the current scope
That means if var is used outside a function, that variable has a global scope. 
If var is used inside a function, that variable has a local scope.
  
 var my_number = 7; //this has global scope

var timesTwo = function(number) {
    var my_number = number * 2;
    console.log("Inside the function my_number is: ");
    console.log(my_number);
};

timesTwo(7);

console.log("Outside the function my_number is: ")
console.log(my_number);
 Out put:
Inside the function my_number is 14
Outside the function my_number is 7

Saturday, 1 February 2014

Hello World,

Start the first day of blogging, with new hope, new Dream. So at starting i would like to introduce My self. I am Keya, Have lots of hopes for my country and my people :) always optimistic. Passed my school and college from Khulna(The most wonderful city In the world) now leaving in Dhaka.

In this world there are lots of things which can help us to organize our life and a great future for the followers, But one thing that is most important and day by day its changing that is the attitude and helping tendency of the people. Now a days the exchange of information became a practice among us. So I decided what ever I learn i will share my views for the followers. Only then we can change our country. Leave the politicians with there situation. Take a step forward to motivate the young talent. Each and every nation need a support system or you can say the back up, I will play my duty..........

So for the first step I have started to learn JAVA. and I will keep update my information... :) Hope it will help a person who is just at the starting point like me.
  
            So nothing is impossible ~KN                                                                   02.01.2014