Skip to content

Instantly share code, notes, and snippets.

@simrananand-2-11
Last active June 17, 2023 08:53
Show Gist options
  • Save simrananand-2-11/c26127672aa89e267109973ec9bb2605 to your computer and use it in GitHub Desktop.
Save simrananand-2-11/c26127672aa89e267109973ec9bb2605 to your computer and use it in GitHub Desktop.
Tanay lecture notes level 0 lecture 1.

Tanay lecture notes

  1. Go to repl.it and sign up on it
  2. Create a repl for node js
  3. Write console.log("Your name here")
  4. Take input from user:
  5. prompt("Give me your name")
  6. Comment using //, or you can use "ctrl + /" to comment whenever you want
  7. Search for "npm readline-sync" in search bar (also read about it on documentation (documentation is a book about any tool, written by people who created that tool))
  8. You can take input using readlineSync
  9. var readLineSync = require('readline-sync');
  10. var userName = readLineSync.question("May I have your userName");
  11. Now, output that userName that you took using console.log(userName);
  12. Welcome your user
  13. var welcomeMessage = "Welcome! Simran";
  14. console.log(welcomeMessage)
  15. Putting placeholder (Placeholder means anything that will act as landmark for some particular information you're looking for.)
  16. var welcomeMessage = "Welcome " + userName; //string concatenation
  17. console.log(welcomeMessage);
  18. Use shortcuts ctrl + / (to comment)(as mentioned earlier)
  19. Play with programs
  20. Programming is input + process + output (Used classic potato chips example)
  21. Quiz part
  22. Conditional programming (if - else)
  23. Save previous 5 programs with name "upto ex 5"
  24. fork and name "ex 6 onwards" (fork means making a copy of current program and working on it also, making sure, previous versions are not affected )
  25. Program's demand : right / wrong using age input (So, are you able to guess my age correctly? Let's see that in upcoming program.😏)
26. var readlineSync = require("readline-sync");
    var score = 0;
27. var userAnswerAge = readlineSync.question("Am i old than 25?"); //input
28. //process
29. if(userAnswerAge === "yes")
30. { 
        console.log("You are right") //output
        score = score + 1;
        console.log("Score is "+ score);//output
    }
31. else 
    {
        console.log("You are wrong") //output
        score = score - 1;
        console.log("Score is "+ score); //output
    }
  1. He assigned us the link. And asked to play with it. (Repl link in description of video of Tanay Pratap's channel under video named "First CLI app: Intro to programming".)

  2. We solved the task assigned to us by Tanay. We added on more question and changed score.

  3. We start with function

  4. Functions

  5. syntax on neogcamp site

39. function add (numberOne, numberTwo)
    {
        var sum = numberOne + numberTwo;
	return sum;
    }
  //use the function 
      var result = add (2,5);<br/>
      console.log("The sum of 2 and 5 is: "+ result);

40.Operators

41. /* + - / * */
  1. livework: function to takes 2 numbers, multiplies them and gives answer;
 function mul(number1, number2):
 {
    var product = number1*number2;
    return product;
 }
 var result = mul(45,23);
 console.log("The product of two numbers is: "+result);

43.// Function q n a

        var readlineSync = require("readline-sync");
    var Score = 0;
    function play(question,answer)
    {
      var userAnswer = readlineSync.question(question);
      
      if(userAnswer === answer)
      {
   		console.log("You were right");
   		score = score + 1;
      }
      else
      {
           console.log("You were wrong");
   		score = score - 1;
      }
    }
    
    // Calling the function
    play("National bird of India? ", "Peacock");
    play("National Anthem of India", "Jan gan man");
        console.log("Your score is: ", score);
  1. for loop basics
45. for(initialCondition, exitCondition, numberOfTimes)
    {
      /*Processing*/
      /* output/return */
    }
46. // print your name 5 times
        for(var i=0; i<5; i=i+1)
		{
			console.log("Simran");
		}
  1. // using for loop bring different questions every time new question should come. This one is DIY
48.This one is another question as part of livework. Break question:
      - Run a loop and print the sum of two numbers. 
      - First number being 22 always, second number being the current value of loop. 
      - Run 10 times. 
      - Print should be: 22,23..
49. for(int iteration = 0; iteration < 10; iteration = iteration + 1)
    {
	   var result = 22 + iteration;
	   console.log("Result after iteration "+ (iteration + 1) + " is "+result);
    }
50. /*
      Three kinds of brackets:
          () => Call a function
          {} => When you have to write a block of code.
          [] => Used to access array elements.
    */ 
  1. Array basics
52. Steps to follow:
        i. Prepare a list of grocery items to buy.
	ii. Add 5 items. Print the first item on the list.
	iii. Print the 3rd item on the list.
	iv. Print the last item on list.
53. var groceryList = ["we","MohanThal","soap",300,"eaw"];
54. console.log(groceryList[0]);
55. console.log(groceryList[2]);
56. var howLongIsThisArray = groceryList.length
    console.log(howLongIsThisArray) 
    console.log(groceryList[groceryList.lenth-1])
57. for(var i=0; i<groceryList.length; i++)
    {
	 console.log(graoceryList[i]);
    }
  1. Objects
59. /*Think about Superman
        name: "superman"
	powers: "flight"
	costumeColor: "blue"
    */
60.var superman = 
   {
		name: "superman",
		power: "flight",
		costumeColor: "blue",
		strength: 10000, 
		stealth: 0
   }
   
   var batman = 
   {
       name: "batman",
       power: "martialArts",
       costumeColor: "black",
       strength: 100,
       stealth: 100;
   }
   
   console.log(superman.strength)
   console.log(batman.strength)
61. Objects in JS: 
               {
   	   key : value 
   	}
  1. Try to print superman's strength, batman's strength, compare both strength
  2. Steps to follow:
    • Create an array of super hero objects.
    • Then print name and costume color of each super hero. Topics covered here: array, for loop, objects, function call. This one is DIY

64.Final game

65. var readlineSync = require("readLine-sync");
     var score = 0;
    var userName = readlineSync.question("What is your name? ");
	console.log("Welcome "+userName+" to DO YOU KNOW <insert-anything-here>?");
	
	//play function
	function play(question,answer)
	{
		var userAnswer = readlineSync.question(question);
		if(userAnswer === answer)
		{
			console.log("right!");
			score = score + 1;
		}
		else
		{
		  console.log("wrong!");
		  score = score -1;
		}
		console.log("Current score: "+ score)
		console.log("--------------------------------")
	}
	
	var questionOne =
	{
	    question: "where do I live? ",
		answer : "Silvassa"
	}
	
	var questionTwo = 
	{
	   question: "My favorite food? "
	   answer: "Home cooked food"
	}
	
	var questions = [questionOne, questionTwo];
	
	_//loop_
	for(var i=0; i<question.length; i++)
	{
	  var currentQuestion = questions[i];
	  play(currentQuestion.question, currentQuestion.answer)
	}
  1. console.log("You scored: ",score)
  2. Do the homeworks assigned. Check neogcamp site. Do homeworks sincerely.
@simrananand-2-11
Copy link
Author

Till point 34. The play part.

@simrananand-2-11
Copy link
Author

Its 15-11-2020 16:16 hrs right now. Completed lecture 1 on video and making notes of it. Will now start to work on it, from step 1 tp last step.
All the best to this part of me. ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment