Cognizant Handson - Feedback Details

FeedBack Details

Feedback Details

Get the feedback details from the user and add it to an array. Display the feedback details in the format as shown in the screenshot.

Concept covered: functions, arrays, control structures and loops, String

Problem Specification:

  1. File name should be index.html.

  2. Create an external script file named script.js.

  3. Use h2 tag for the title of Feedback Details.

  4. Display all the feedbacks followed by a new line separator after printing the above title.

  5. Refer Sample screenshot for more specifications.

  6. Include the script file in html page.

  7. The "Add Feedback" button will add the feedback details to an array.

  8. The "View Feedback" button will display all the feedbacks (multiple feedbacks) in the format as shown in the screenshot in the result div.

  9. Include the below functions/methods in the java script file

  Function Name

Description

addFeedback()

It is used to add the feedback details to an array. After clicking the Add Feedback button, clear the text area and display the response message as "Successfully Added Feedback Details!".

displayFeedback()

It is used to display the feedback details. After displaying the feedback details clear the array.

 

[Note:Strictly adhere to the specifications given in the screenshot. Use the same id names for all the corresponding fields specified.]

Sample Input/Output:

Screen1:

Screen 2



Screen 2.1


Screen 3


Solution:

index.html

<html>
<head>
    <script src="script.js" type="text/javascript"> </script>
  </head>
  <body> 
    <h2 id="">Feedback for the ART OF LIVING session</h2>
    <label for="feedback">Enter the Feedback:</label>
    <textarea type="text/submit/hidden/button" name="feedback" id="feedback" value="" ></textarea>
    <br />
    <button type="submit" id="create" onclick="addFeedback()">Add Feedback</button>
    <br />
    <button type="submit" id="view" onclick="displayFeedback()">View Feedback</button>
    <div id="result">
    </div>
  </body>
</html>

 script.js

var feed=[];

var x=0

function addFeedback(){

    //Fill the required logic  

    var feedback=document.getElementById('feedback').value;

    feed.push(feedback);

    document.getElementById('feedback').value="";

    document.getElementById("result").innerHTML="<h2>Feedback Details</h2><h3>Successfully Added Feedback Details!<h3>";

}


function displayFeedback(){

    //Fill the required logic

    var txt="";

    var count=1;

    for (var i =1; i < feed.length+1; i++) {

        txt+="Feedback "+i+"<br>"+feed[i-1]+"<br>";

    }

    document.getElementById('result').innerHTML="<h2>Feedback Details<h2>"+txt;

}

   



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.