Ved Prakash JavaScript Exercise Session 1st - Solutions with explanation | codinggiri GuidePedia


Hey there welcome once again Hope you are enjoying learning coding :) . In this post i am going to post the answer of those 5 questions which was  posted in last blog post.
  • Use the console.log or alert , to Display this simple message:
  • "Hello ! JavaScript"
    Here is the answer
      console.log("Hello ! JavaScript");
    or you can use the alert method too
      alert("Hello ! JavaScript");
  • Take three variables a,b and c. assign some integer values to first two variables a and b. now show assign (a and b) sum (+) , diffrence(-) and multiplication(*) values in to variable c
  • Here is the answer
      var a = 10; /*Assigning the value of a to 10*/
            var b = 5; /*Assigning the value of b to 5*/
            var c = a+b; /*Telling the interpreter that value of c is equal to sum of a and b */
            alert(c); /*Displaying the result */
    Please follow the comments
  • Take a variable A, now use prompt to ask user his/her name and print a greeting message.
  • Here is the answer
      var a = prompt("What is your name: ");
      /*Take a variable a 
      then ask user to enter his/her name nad store the value entered
      by user into variable a
      alert("Nice to Meet you " + a); 
      /*Now use the alert method to 
       disply the greeting message 
  • Take a variable A and print the square value.
  • we will use mathematical operator to square the value
      var a = prompt("Please give me a number: ");// store the value entered by user in variable a
      a = parseFloat(a); // This may sound tricky but we will cover it later
      var b = Math.pow(a,2); // This is pow method in JS
      b = parseFloat(b); 
      /*Overall this answer may bounce over from your head but don't
      you worry you will master them all soon just saty tuned 
      and read my next posts
  • We are going to find out the area of a rectangle so for that Take Three variables named first,second and Final. use prompt to ask user to give the length and width, then store the area of rectangle into third variable and finally print the area.
  • Here is the answer
     var first = prompt("Please tell me the length: ");/*store value of length in variable first*/
     first = parseFloat(first); /*Now convert the entred value into float*/
     var second = prompt("Please tell me the width: ");/*store the value of width in variable second*/
     second = parseFloat(second); /*Now convert the entred value into Float*/
     var final = (first * second); /*value of final is equal to the multiplication of first and second (variables) */
     final = parseFloat(final); /*Again convert the value of final in float with parseFloat*/
     alert("The area of rectangle is " + final ); /*Finally display the result like a boss*/
    So folks i hope you can understand the explained answers and agian if you are facing any problem feel free to comment below and let me know i'll surely help you out

Post a Comment