I have issue implementing DOM manipulation

although I think, I should place this in JS but this isn’t related to the curriculum JavaScript, and this isn’t about Contributors in my mind at least, any here is my issue.

I was tackling this issue Not allowing type attribute in Step 7 · Issue #46078 · freeCodeCamp/freeCodeCamp (github.com)

my first approach, which didn’t work is


//Your code should have a `link` element.

assert(document.querySelector('link'))


//Your `link` element should have a `rel` attribute with the value `stylesheet`.

assert(document.querySelectorAll('link')?.getAttribute('rel') === 'stylesheet');


//Your `link` element should have an `href` attribute with the value `styles.css`.

const stylesFileFirstVersion = document.querySelectorAll('link')?.getAttribute('href') === 'styles.css'
const stylesFileSecondVersion = document.querySelectorAll('link')?.getAttribute('href') === './styles.css'

assert(stylesFileFirstVersion | stylesFileSecondVersion)

the step Learn the CSS Box Model by Building a Rothko Painting: Step 7 | freeCodeCamp.org

it’s file is this freeCodeCamp/60a3e3396c7b40068ad69970.md at main · freeCodeCamp/freeCodeCamp (github.com)

I am wondering, what am I missing for this to fail? btw it fails in the first test Your code should have a link element

how about this, suggested snippet from that issue link

have you tried this out?!

1 Like

I don’t think you can use getAttribute on an html collection

what do you mwan that it fails?
is it a false positive or a false negative?

1 Like

Hey ilenia, It’s false negative. It fails

<link rel="stylesheet" type="text/css" href="styles.css">

Edit:

I don’t think you can use getAttribute …

Interesting I didn’t know that, I will alter my code, but I need to pass the first one.

hey bappyasif, it works but it’s too strict for my liking.

why are you using ‘querySelectorAll’ wouldnt you be using ‘querySelector’?

as former gives you a list of nodes, where as later gives you a specific or ‘found first’ node!!

I kept in mind that someone may have added extra link, I was planning to hint about only needing one link like in description later, but it failed my first step which halted everything

well, they shouldnt!! at least for this, it’s a test case!!

that’s just my view!! please, feel free to explore :slight_smile:

update, I have tested it again, I think I have mistaken categorised it as false negative.

anyway here are images of my test

image


image


image


at least now I know better where is the issue, I can go from there thanks ilenia