From d560ce1444a0101fa9c36a7e6b48620fb4d062b1 Mon Sep 17 00:00:00 2001 From: Mariani Giacomo <mariang1@t31300-lr138.org.aalto.fi> Date: Wed, 25 Mar 2020 12:13:23 +0200 Subject: [PATCH] added query selector all exercise --- content.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/content.js b/content.js index 4fcd3a5..9510586 100644 --- a/content.js +++ b/content.js @@ -346,6 +346,48 @@ let Content = { order: 12 }, + query_selector_all: { + instructions: `The text of the pizza toppings is wrong, help us fix it. + Find all the <code>li</code> elements within the <code>ul</code> element with + <code>id="pizza-topping"</code> using the <code>document.querySelectorAll()</code> + method. Then fix the <em>innerText</em> of each element.`, + initialJs: '', + preExecuteJs:` + let consolePrint = []; + const originalLog = console.log; + console.log = function(msg) { + originalLog(msg); + display.res(msg, [msg[0].innerText, msg[1].innerText, msg[2].innerText, msg[3].innerText]); + }; + let listDiv = document.createElement('div'); + listDiv.innerHTML = '<h3>Pizza toppings:</h3><ul id="pizza-toppings"><li>Batsilica</li><li>Tomtato</li><li>Morezarella</li><li>Hamster</li></ul>' + document.body.appendChild(listDiv) + `, + executeAtStart: true, + points: function ($element, config, accessor) { + let toppingsInaccessor = document.querySelectorAll('#pizza-toppings li'); + let correctNames = [ 'BASILICA', 'TOMATO', 'MOZZARELLA', 'HAM']; + let p = accessor.testResults(10, function(i , args, res) { + console.log('res:', res); + console.log('args:', args); + let points = 0; + args.forEach((item, i) => { + console.log('In testResults', item) + if(item.toUpperCase() === correctNames[i]) { + points += 2.5; + } + }); + return points; + }); + return { points: p }; + }, + maxPoints: 10, + title: "Select and modify the right element", + description: "", + concepts: ["JavaScript", "querySelectorAll", "id"], + order: 13 + }, + }; module.exports = Content; -- GitLab