← 2023 questions

2023 / INSTAGRAM / QUESTION 5

Post interactions

Try the question in your own editor, then check your output below.

THE QUESTION

Here are a few arrays that represent properties such as number of likes, number of comments and number of views in Finnick's feed.

posts = [1, 2, 3, 4, 5]
likes = [0, 0, 0, 0, 0]
comments = [[], [], [], [], []]
views = [0, 0, 0, 0, 0]

Use these arrays to do the following:

asks the user for an input as to which post he wants to view

every time the user views the element, increment the number of views by 1

include functionality for likes and comments such as incrementing likes and appending comments

Question by Dhivyesh. Source: Girls In Code SEA — Behind the Screens, 2023, slide 19.

PRACTICE CHECK

Try your answer.

New interaction sequence for checking the original app behaviour.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

Starting with the original empty arrays: view post 3 twice, like it once, and comment “Great!”. Enter its final views, likes and number of comments.

Enter the comments as a list.

Reveal worked answer

Post 3 state

[2, 1, 1]

Comments for post 3

["Great!"]

Each view adds one, one like adds one, and appending the comment leaves a one-item comment list.