Not logged in : Login

About: Comment 2 by (john49)     Goto   Sponge   NotDistinct   Permalink

An Entity of Type : sioc:Post, within Data Space : ods-qa.openlinksw.com:8896 associated with source document(s)

AttributesValues
type
Date Created
  • 2020-10-12T14:27:36.910Z
Date Modified
  • 2020-10-12T14:33:29.177Z
label
  • Comment 2 by (john49)
discourse:topic_slug
  • loops-2-test-help-needed
discourse:post_number
  • 2
discourse:quote_count
  • 0
discourse:incoming_link_count
  • 1
discourse:score
  • 7.8
discourse:topic_id
  • 68977
described by
has container
content
  • proxy:entity/https/discourse.mozilla.org/t/loops-2-test-help-needed/68977#content_168260

    Hello BattleCat! You forgot to access the object’s properties: phonebook is an array of objects, so if you want to access the name property of the ith element (object) of the array, you have to write phonebook[i].name (phonebook[i] is the object itself, which you can’t compare with the string name; that’s why the if statement was always false).

    Here is the correct code, where I also added a new variable, phonebookEntry, to store the current element within the loop:

    for (let i = 0; i < phonebook.length; i++) {
        let phonebookEntry = phonebook[i];
        if (phonebookEntry.name === name) {
            para.textContent = `${phonebookEntry.name} : ${phonebookEntry.number}`;
            break;
        } 
        // ...
    

    Best regards!

discourse:reply_count
  • 0
author
is has reply of
Faceted Search & Find service v1.17_git55 as of Mar 01 2021


Alternative Linked Data Documents: ODE     Content Formats:       RDF       ODATA       Microdata      About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 08.03.3322 as of Mar 14 2022, on Linux (x86_64-generic-linux-glibc25), Single-Server Edition (7 GB total memory)
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2024 OpenLink Software