Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS Objects › Student object
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<pre id="out"></pre> <script> const student = { name: 'Asha', marks: { html: 88, css: 92, js: 79 }, average() { const list = Object.values(this.marks); return list.reduce((a, b) => a + b, 0) / list.length; } }; student.city = 'Gaya'; let text = `${student.name} from ${student.city}\n`; for (const [subject, mark] of Object.entries(student.marks)) { text += `${subject.toUpperCase()}: ${mark}\n`; } text += 'Average: ' + student.average().toFixed(1); document.getElementById('out').textContent = text; </script>
Result