学習開始


JavaScriptの基礎知識

Learn to appreciate yourself and celebrate small wins --- これは、動機付け続ける

JavaScriptの基礎知識


はじめに


JavaScriptは(“JS”ショート用)は、ウェブサイトに対話を追加することができます本格的な動的なプログラミング言語です.それはBrendan Eich(Mozilla Project、Mozilla財団とMozilla社の共同創設者)によって発明されましたJavascript 今まで.

2 .こんにちは世界!


console.log("Hello World!");

//console.log() is one of the javascript inbuilt function which allows us to print anything in the code at the output.

利用者からの入力


プロンプトはJavaScriptの作り付け機能で、ユーザー入力を入力するダイアログボックスを作成します.しかし、これはブラウザコンソールでのみ動作します.この入力方法は示唆されないが、その存在を学ぶ.
prompt("What is your name?");

変数


JavaScriptは、値を格納するコンテナを含みますVariables
var myName = "Jaswanth";
var myAge = 19;
let myPlace = "Rajahmundry";
.
.
.
//many things were there to know about these variables, so go through the above link.

JSのデータ型


データの種類は異なった名前の名前でした.Data types integer、string、character、float、booleansのように.とアドインArray , そして、より多く.我々は彼らの外出先で学びます.
これらから離れて、あなたも知っているべきですtype coercion
var integer= 723; // It is a Integer(number);
var deciamalNumber = 200.76349; //It is a Float(decimal number)
var str = "Javascript is a scripting language."  //It is String(text)
let bool = True //Boolean (True or False)

条件文


if文::コードの一部を実行するために条件が満たされているかどうかを確認します.
もしそうならば、それが文が本当であるならば、コードがifか他の内で囲まれる部分を実行するように、それはふるまいます
はelse文で囲まれます.
nested if ::もしステートメントがtrueの場合、if文の中にあるif if文をチェックします.
もしそうならば- else - - else ::これは、条件が真実でないならば、似ています.
if
// if statement-syntax

var myAge = 19;
if(check_condition){
    //if true execute statements inside this
}


//if statement - example

if (myAge >=18){
    console.log("you are above 18);
}
他ならば
//if-else  - syntax

if(check_condition){
    //if true execute statements inside this
}
else{
    //if false execute statements inside this
}


//if-else  - example

var myAge = 16;
if (myAge >= 18){
    console.log("you are above 18);  //does not execute this
}
else{
    console.log("you are below 18);  //executes and prints "you are below 18"
}
ネストした
//syntax

if(check_condition-1){
    //if true
    if(check-condition-2){
        //if true
        if(check-condition-3){
            ... // this goes on till every check condition is true
        }
    }
}

* if any of the check condition is false it comes out and executes the rest of the statements below that if statement. *

//example
var myAge = 19;
var myName = "Jaswant";
if(myAge >= myAge){     //condition is true
    if (myName == "Jaswanth"){ //condition is false
        console.log("You are Jaswanth");
    }
    console.log("You are",myAge);
}

output -
You are 19

ループ


開発者は、「乾いた」原則に従います.したがって、ループ、関数、アルゴリズム、パターン、および多くを使用します.今、我々はループとは何かを学ぶことができます.
ループ処理は、ループ文内の条件がfalseになるまで複数回の文を実行するという概念です.
ループの種類についてはこちらを参照ください.
  • for loop
  • の構文
    for(INITIALIZATION, CHECK_CONDITION, INCREMENT/DECREMENT){
        //set of statements to be executed
    }
    
    例えば
    for(let i=0; i<5; i++){
        console.log("hello..");
    }
    
    // let i = 0  -->  initialize i = 0;
    // i<5 --> checks wheather the value of i is less than 5
    // i++ --> increment the value of i by 1 value(i=i+1)
    //This loop runs for 5 times and print "hello.."
    hello..
    hello..
    hello..
    hello..
    hello..
    
  • while
  • 一方-構文
    //
    while(CHECK_CONDITION){
        //set of statements to be executed
    }
    
    例ですが
    var i = 0;
    while(i<5){
        console.log("hello..");
        i++;
    }
    
    //This loop runs 5 times and print "hello.."
    hello..
    hello..
    hello..
    hello..
    hello..
    
    

  • do while -- これは、条件が満たされていないとしても、ループが最初に1回だけ実行される特殊なwhileループです.
  • do-while  - syntax
    do{
        //set of statements to be executed
    }while(CHECK_CONDITION);
    
    //do-while  - example
    let k=10;
    do{
    console.log(k);
    k++;
    }while(k<0)
    
    //output -
    10
    

    関数


    関数は、入力を渡して出力を取得することにより、特定の関数セットを実行するために使用されました.我々は、関数を別の入力で複数回呼び出すことができますし、同じタスクを実行し、異なる出力を取得するたびに(異なる入力).
    //defining a function - syntax
    function FUNCTION_NAME(PARAMETERS){    //parameters are the optional inputs which were received by the function to do something with them and give output
        //set of statements to be executed when function is called
    }
    
    //function calling - syntax
    FUNCTION_NAME(ARGUMENTS); //argumentss are the optional values which were to be passed to functions as inputs for that function
    
    //example
    function printName(name){  //name is parameter
        console.log("Hi " + name);
    }
    
    //calling a function
    printName("Tanay");     // Tanay is an argument --> this print :  "Hi Tanay"
    printName("Akanksha");     // Akanksha is an argument--> this print :  "Hi Akanksha"
    

    プロジェクトの設定

  • 移動するrepl (REPLを探る、それを使用する面白いWebアプリです).
  • さて、REPLに新しい場合は、新しいアカウントを作成します.
  • 新しいREPLを開き、ノードを選択します.ノードの下のJS.js
  • これで、JavaScriptにノードを入力します.コンソール.
  • それを使用するには時間がかかる混乱しないでください.あなたの自由な時間の探検repl.
  • クイズプロジェクト


    さて、簡単なJavaScriptとNodeJSプロジェクトに入りましょう.この単純なプロジェクトでは、シンプルなコマンドラインインターフェイスのクイズを構築します.プロジェクトをしている間、最終的にプロジェクトを構築しましょう.
    私たちはこのプロジェクトを行うことによって学びますか?
  • 入力を取る(' readline sync ' NPMパッケージ)
  • 印刷出力
  • 演算子の使用
  • ifとifの使い方
  • forループの使用法
  • 配列、辞書のような基本的なデータ構造の使用
  • このプロジェクトを作成する目的は、マーベルについてのクイズを作成することです

    ユーザー入力を取るために、我々は「readline sync」と呼ばれているNPMパッケージを使います


    このパッケージをライブラリに使用するには、以下のコードを入力し、プロジェクトに利用できるようにします。


    var readlineSync = require('readline-sync')
    
    今PlayerRound名を入力し、歓迎メッセージを印刷します\n 'はエスケープ文字です.エスケープ文字について知っているstrings .
    var playerName = readlineSync.question("Enter your name: ");
    console.log("Welcome to the quiz ",playerName+"\n");
    
    PlayerRankスコアを初期化
    var playerScore = 0;
    
    サンプルを作りましょうarray 3つの質問objects
    const generalQuiz = [
        {
            question: "Who is the prime minister of india?",
            a: "Tanay Pratap",
            b: "Bumrah",
            c: "Narendra Modi",
            d: "Dhoni",
            correctAnswer: "c"
    
        },
        {
            question: "Who is the president of america?",
            a: "Jaswanth",
            b: "James Cameron",
            c: "Kamala Harris",
            d: "John Beiden",
            correctAnswer: "d"
        },
        {
            question: "Which is the largest continent?",
            a: "Asia",
            b: "Africa",
            c: "South America",
            d: "Europe",
            correctAnswer: "a"
    
        },
    ]
    
    さて、配列内の各項目として配列とオブジェクトを使用しました.今、我々は我々のプレーヤーのためにこれらの質問を印刷する必要があります.だから我々はfor 今すぐループ.
    我々はループのために、すべての質問を繰り返すために使用する必要があります場合は、答えが正しい場合、我々はPlayerRankスコアに1を追加することができます.
    // we declare function so that the function playQuiz takes in different objects but conducts and evaluate quiz
    
    function playQuiz(quiz){
        for (let i = 0; i < quiz.length; i++)
        {
            console.log(`${i + 1}. ${quiz[i].question}`);
            console.log(`          a: ${quiz[i].a}`);
            console.log(`          c: ${quiz[i].b}`);
            console.log(`          b: ${quiz[i].c}`);
            console.log(`          d: ${quiz[i].d}`);
            var answer = readlineSync.question("Answer: ");
            console.log("\n");
    
            //now validate answer
            if (answer.toLowerCase() == quiz[i].correctAnswer){
            playerScore = playerScore + 1;
            }
        }
        return playerScore;
    }
    
    今、プレーヤーが正しくスコアが増加するたびに答えます.
    最後に最後にユーザーのスコアを印刷します.
    let finalScore = playQuiz(generalQuiz); // here we called the playQuiz function and stored the final score of the player in finalScore variable.
    
    console.log("Woohooo!!, you scored "+finalScore);   // printing final score.
    

    出力



    ああ!あなたはCLIプロジェクトをしました、しかし、それがあなたのファンダメンタルズを造る際にあなたを助ける単純であるけれども.
    あなたがJavaScriptの基礎を学んだことを望みます

    上記のコード遊びクイズ


    JavaScriptリソースを探る

  • MDN DOCS
  • Eloquent Javascript book

  • You don't know javascript
  • あなたのフィードバックは、このドキュメントを改善するのに役立つでしょう❤


    あなたがドキュメンテーションが好きであるならば、[email protected]