An erroneous if statement in JavaScript is being triggered

I have a series of if statements that output different strings from corresponding lists based on the input (feelsLike).

View Code

Initially, it identifies the range in which feelsLike falls and then concatenates all items in the list into the string. When checking the console, even though feelsLike is 14, it seems to execute the console.log statement within the second if statement (6 <= feelsLike <= 9). Can someone kindly point out what mistake I might be making?

View Console Output

Answer №1

6 <= feelsLike <= 9

The current code logic is not working as intended. It is not evaluating whether feelsLike falls between 6 and 9. Instead, it checks if 6 <= feelslike, resulting in either true or false. If false, the comparison becomes false <= 9, which doesn't logically make sense. JavaScript then converts false to 0 (true becomes 1). Since 0 is less than or equal to 9, the final result is considered true.

To fix this issue, use

6 <= feelsLike && feelsLike <= 9

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to retrieve all collections and their respective documents in Firestore using cloud functions?

Seeking to retrieve an array structured as [1year, 1month, etc] with each containing arrays of documents. Currently encountering a challenge where the returned array is empty despite correct snapshot sizes. Unsure if issue lies with push() method implemen ...

Has a newly created element been styled or are all values set to default since it is outside of the DOM?

First, I begin by creating an element: let link = document.createElement('a'); After my document is fully loaded and all styles and scripts are applied. The styles may look something like this: a { background-color: salmon; } Therefore, it w ...

IE displaying "slow script" alert due to Knockout malfunction

Within my grid of observables and computed observables, the first row serves as a multiplier for all subsequent rows. Users can modify this percentage rate and Knockout automatically updates all relevant values accordingly. Additionally, I require a textbo ...

Tips for setting up Craigslist email forwarding through Node.js (receiving emails to a dynamically generated email address and redirecting them)

After extensive searching, I only came across this Stack Overflow post about Email Forwarding like Craigslist in Rails: Email Forwarding like Craigslist - Rails I spent a significant amount of time googling, but couldn't find any solutions using Node ...

Retrieving Twitter posts using the screen_name parameter in a Node.js environment

I am looking to create a website that allows users to enter the Twitter screen name of any celebrity. When the user clicks on the "show tweet" button, the latest tweet from that screen name will be displayed. I am interested in implementing this feature ...

Exploring the integration of functions from external JavaScript libraries into Angular factories and controllers

Is there a way to incorporate the functions from these libraries into my Angular factory? <head> <script type="text/javascript" src="js/3rdparty/strophe.js"></script> <script type="text/javascript" src="js/3rdparty/xml2json.js">< ...

Leveraging three.js through a content delivery network with the option of incorporating either S

Is it possible to optimize my Svelte or React application by declaring the Three.js module as a script tag that calls the module from a CDN instead of importing it via npm? I want to capitalize on the benefits of a framework while minimizing my final bundl ...

Refreshing the page triggers the callback function that retrieves the checkboxes selected in a Kendo treeview component

How can I retain the selected checkboxes after refreshing the page? Is there a way to achieve this using AJAX when submitting data to a database and then reloading the page? AJAX //AJAX call for button $("#primaryTextButton").kendoButton(); va ...

How to incorporate Base64 textures into Three.js

I am currently trying to load textures from URLs, but since my backend code is generating planets, I need to display them using Base64 instead. I'm experimenting with procedural generation, so I'd rather not save the image and then load it via U ...

Ways to utilize the this.context.router in ReactJS

Below is the code I have written: import React from 'react'; import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table' import sampleSystems from '../sample-systems'; class SystemTable extends React.Component ...

Adjusting specific sections of a container in real-time

Fiddle: https://jsfiddle.net/1b81gv7q/ Sorry for the slightly cryptic title; I couldn't come up with a better way to phrase it. Imagine this scenario: there's a container with content that needs to be dynamically replaced. If I wanted to repla ...

Code snippet causing element block JavaScript malfunction

I'm attempting to create a basic automatic slideshow using JavaScript. let currentIndex = 0; startSlideshow(); function startSlideshow() { let slides = document.getElementsByClassName("slide"); for (let i = 0; i < slides.length; i++) { ...

Assigning names to the points on the AxisHelper component in THREE.js

Take a look at the code snippet provided below: <html> <head> <title>My first Three.js app</title> <style>canvas { width: 100%; height: 100% }</style> </head> <body ...

Why won't angularjs interpret my object accurately?

Currently, I am in the process of developing an angularjs application and I have encountered a minor issue. The problem arises when I populate a list of projects and then apply filtering based on certain conditions. Visually, everything appears fine on the ...

Using JavaScript to only update the CSS background image when the source image changes

Is it feasible to dynamically update the CSS image referenced by a provided URL in "background-image: \"<some-url>\" using JavaScript, but only when the source image is modified on the server? The idea is to cache the image a ...

How to Implement a Dynamic Background Image Change with JavaScript on Scroll

Can someone help me with changing the background image on my webpage's body when it has been scrolled past a certain point? I've managed to make the initial change, but when scrolling back up, the first background image is still replaced. Being n ...

Showing JSON information fetched from an AJAX request within an HTML page

I've been working on a project and I'm almost there with everything figured out. My main challenge now is to display an array of items on a web page after making an ajax call. Below is the code snippet I currently have: JQuery Code: var su ...

What are effective ways to work around the CORS policy while making get/post requests from within React JS?

My React JS application is encountering an issue with CORS policy while trying to fetch data from servers in other domains. Despite using http-proxy-middleware and setting up the necessary proxy, I am still unable to make successful get/post calls to the e ...

Incorporating JSON into a Yahoo! widget

Help! I was reading the Yahoo! Widgets spec and it mentioned that I can parse JSON objects using JSON.parse(). So, being curious, I tried it out with this code snippet... var parsed = JSON.parse('{"key": "value"}'); console.log(parsed); for ( ...

Removing an item from an array using AngularJS with Underscore or another method

Although my question may seem similar to others, it is unique! Please review to understand my specific situation. I am dealing with an array of objects that looks like this $scope.events =[ { $$hashKey: "009" _allDay:false _i ...