Untitled
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
``` // Define User class class User { constructor(name, age, gender, interests) { this.name = name; this.age = age; this.gender = gender; this.interests = interests; } // Define a method to display a user's profile showProfile() { console.log("Name: " + this.name); console.log("Age: " + this.age); console.log("Gender: " + this.gender); console.log("Interests: " + this.interests.join(", ")); } } // Define Posts class class Post { constructor(author, title, body) { this.author = author; this.title = title; this.body = body; this.comments = []; } // Define a method to add a comment to a post addComment(comment) { this.comments.push(comment); } } // Create some users and posts let alice = new User("Alice", 25, "female", ["hiking", "reading"]); let bob = new User("Bob", 30, "male", ["biking", "movies"]); let post1 = new Post(alice, "My hiking trip", "I went on a beautiful hike today!"); let post2 = new Post(bob, "My movie review", "I saw a great movie last night!"); // Display their profiles and posts alice.showProfile(); bob.showProfile(); console.log(post1); console.log(post2); // Add comments to posts post1.addComment("Sounds awesome!"); post2.addComment("I'll have to check it out."); console.log(post1); console.log(post2); ``` This is just a simple starting point, but you can add more features and functionality such as messaging, search, likes and dislikes, hashtags, and more based on your app's requirements. This message has been generated by Nova - download it for free: https://novaappai.page.link/r9DkVApdFoaxJgWy9
Editor is loading...