第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

嘗試從 JavaScript 在 HTML 頁面上顯示段落

嘗試從 JavaScript 在 HTML 頁面上顯示段落

慕田峪7331174 2022-08-04 10:36:28
我的 JavaScript 有問題。我正在嘗試顯示向用戶顯示移動電話的用戶首選項(xiàng)的操作的結(jié)果。當(dāng)我在Web瀏覽器中測試此代碼時(shí),我看到一個(gè)空白的網(wǎng)頁,JavaScript控制臺中沒有錯(cuò)誤。我在這里做錯(cuò)了什么嗎?下面顯示的是我的代碼。// This is an array of the objects in the website, showing the phone information that will be used to filter for the user to view. const phones = [{  name: "iPhone XS", brand: "Apple", cost: 43, data: "500MB", minutes: "Unlimited", texts: "Unlimited"},{  name: "iPhone 11", brand: "Apple", cost: 64, data: "90GB", minutes: "Unlimited", texts: "Unlimited"},{  name: "Galaxy S10", brand: "Samsung", cost: 30, data: "20GB", minutes: "Unlimited", texts: "Unlimited"},{  name: "Galaxy S10", brand: "Samsung", cost: 65, data: "Unlimited", minutes: "Unlimited", texts: "Unlimited"},{  name: "Galaxy A10", brand: "Samsung", cost: 11.99, data: "500MB", minutes: 250, texts: "Unlimited"},{  name: "Galaxy S9", brand: "Samsung", cost: 31, data: "20GB", minutes: "Unlimited", texts: "Unlimited"},{  name: "StarTAC 130", brand: "Motorola", cost: 3, data: "0MB", minutes: 200, texts: 500},{  name: "Pixel 3A", brand: "Google", cost: 23, data: "4GB", minutes: "Unlimited", texts: "Unlimited"},{  name: "Xperia 10", brand: "Sony", cost: 30, data: "20GB", minutes: "Unlimited", texts: "Unlimited"},{  name: "P30", brand: "Huawei", cost: 27.99, data: "500MB", minutes: 500, texts: "Unlimited"}]// These are asking the user for entry of the data into the system.const phoneBrand = prompt("Enter a phone brand")const phoneCost = prompt("Enter a monthly cost")const phoneData = prompt("Enter the amount of data")const phoneMins = prompt("How many minutes?")const phoneTexts = prompt("How many texts?")// This is then filtering the object of phones to match what the user has entered into the system.const matchingPhones = phones.filter(function(phone) {    if(phone.brand===phoneBrand && phone.cost.toString()===phoneCost && phone.data===phoneData && phone.minutes.toString()===phoneMins && phone.texts.toString()===phoneTexts) {        return true;    }    return false;
查看完整描述

1 回答

?
肥皂起泡泡

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊

我確實(shí)得到了這個(gè)回應(yīng),#1確保在定義Javascript之前定義returnPhones div:


<div id="returnPhones">


</div>

我已經(jīng)測試了下面修改后的代碼,它的工作原理:


    const phones = [{

    name: "iPhone XS", brand: "Apple", cost: 43, data: "500MB", minutes: "Unlimited", texts: "Unlimited"

},

    {

        name: "iPhone 11", brand: "Apple", cost: 64, data: "90GB", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "Galaxy S10", brand: "Samsung", cost: 30, data: "20GB", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "Galaxy S10", brand: "Samsung", cost: 65, data: "Unlimited", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "Galaxy A10", brand: "Samsung", cost: 11.99, data: "500MB", minutes: 250, texts: "Unlimited"

    },

    {

        name: "Galaxy S9", brand: "Samsung", cost: 31, data: "20GB", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "StarTAC 130", brand: "Motorola", cost: 3, data: "0MB", minutes: 200, texts: 500

    },

    {

        name: "Pixel 3A", brand: "Google", cost: 23, data: "4GB", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "Xperia 10", brand: "Sony", cost: 30, data: "20GB", minutes: "Unlimited", texts: "Unlimited"

    },

    {

        name: "P30", brand: "Huawei", cost: 27.99, data: "500MB", minutes: 500, texts: "Unlimited"

    }]


// These are asking the user for entry of the data into the system.

const phoneBrand = prompt("Enter a phone brand")


const phoneCost = prompt("Enter a monthly cost")


const phoneData = prompt("Enter the amount of data")


const phoneMins = prompt("How many minutes?")


const phoneTexts = prompt("How many texts?")


// This is then filtering the object of phones to match what the user has entered into the system.


const matchingPhones = phones.filter(function(phone) {

    if(phone.brand===phoneBrand && phone.cost.toString()===phoneCost && phone.data===phoneData && phone.minutes.toString()===phoneMins && phone.texts.toString()===phoneTexts) {

        return true;

    }

    return false;


})


// This is then displaying data in the system.


const returnPhones = document.querySelector("#returnPhones");


matchingPhones.forEach(function(phone) {


    const newParagraph = document.createElement("p");

    newParagraph.textContent='The matching plans are as follows - ' + phone.name;

    returnPhones.appendChild(newParagraph);


})


查看完整回答
反對 回復(fù) 2022-08-04
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號