JavaScript statements yielding results

Currently, I am in the process of learning Javascript. My latest project involves writing a JS script to return a Json-type value.

  var generateUrl = function(Name, Letter, rootUrl, V1) {
  rootUrl = rootUrl || Letter;
  return  {
    classname: 'mycss-' + Letter,
    text: Name,
    url: rootHref.replace(Rex, "$1" + rootUrl + "."),
    onclick: {
      fn: clickFn,
      obj: V1
    }
  };
};

My current challenge is adding an if statement inside the url: section of my code. Specifically, I want the url logic to behave differently if the Name = google. In this case, I don't want to use the existing

rootHref.replace(Rex, "$1" + rootUrl + ".")
logic but rather directly return a different url.

I've been searching for a solution for some time now without success. Can someone please guide me on how to incorporate an if statement logic into my code?

Answer №1

Consider trying this approach

 website: (num === 1) ? LinkOne : LinkTwo,

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

Combining multiple 'Eithers' and 'Promises' in fp-ts: A guide to piping and chaining operations

Recently, I began working with fp-ts and wanted to create a method with functional-like behavior that would: Parse a bearer token Verify the validity of the user using the parsed token import { Request } from 'express'; import { either } from & ...

Map Loader for GeoJson Leaflet Integration

Although my English skills are not perfect, I will do my best to explain my issue. I have some knowledge of javascript / html / ajax and I have created a webgis using Leaflet. The problem arises when loading a large geojson file onto the map - it takes qui ...

Utilize the power of checkboxes in Vue.js and Quasar framework to enable specific functionalities upon being

There are two checkboxes available: 'Show Active' and 'Show Live'. Initially, the 'Show Live' checkbox is disabled. I need a feature where if 'Show Active' is checked, it will enable the 'Show Live' checkb ...

Tips for modifying the default settings of a CSS framework like Material UI

Exploring the realm of CSS for the first time and feeling a bit lost. I am working with material ui alongside react and redux. My goal is to customize certain properties of a specific component, such as TextField with the disabled attribute. Upon inspectin ...

Is it possible to utilize gulp to eliminate all require.js define([...]) wrappers throughout the codebase?

Is it possible to test my app without using require.js in order to assess the performance and file size if all files were concatenated into a single one? I'm contemplating using gulp to gather all *.js files in the app, running a gulp-replace to elim ...

How to Implement Flexbox Display Across Various Browsers Using jQuery?

Running into an issue here. I'm trying to switch from display: none to display: flex, display: flex-box, and display: -ms-flexbox but for some reason it's causing errors in my code.. Here's what I've been working on: $(elem).css({&apos ...

Move the internal array pointer forward to the next record in order to apply the insertAfter function within the jquery code

As a new jQuery user, I'm attempting to develop a jQuery function using data provided by PHP. My goal is to arrange DIV elements in order of their values using insertAfter method. However, I seem to be encountering some difficulty in advancing the poi ...

"Using jQuery to ensure multiple sections are ready for manipulation on

After some experimentation, I made an interesting discovery: I can actually include $(document).ready(function(){}); multiple times. For example: $(document).ready(function(){ var abc = "1122"; //do something.. }); $(document).ready(function() ...

- "Queries about Javascript answered with a drop-down twist

Having some trouble with setting up a straightforward FAQ dropdown feature. Could someone lend a hand and see what might be going wrong? Appreciate your help! CSS #faqs h3 { cursor:pointer; } #faqs h3.active { color:#d74646; } #faqs div { height:0; o ...

Sort your Laravel pagination table effortlessly with just one click

Here is my current setup: <table class="table table-striped"> <tr> <th> Item Image </th> <th> Item Number </th> <th> Item Name </th> <th> Description </th> ...

"Switching to a new request in jqgrid will automatically cancel the current

I am using a jqgrid on my website to display data in JSON format retrieved from the server. The grid includes some blank cells which users can double-click on to update the data. However, I have encountered a problem where if I click too quickly on multipl ...

Adding information into material-ui dropdown using React JS

I could use some assistance with populating data into a Dropdown using material-ui in React. I am new to React and unsure about how to achieve this. I know that I can pass props to the dropdown, but it's not very clear to me. Here is my current code: ...

"Enhance User Experience with Material UI Autocomplete feature that allows for multiple

I am encountering an issue with a material ui auto component that I am currently working on. The component's code looks like this: <Autocomplete multiple options={props.cats} defaultValue={editRequest? ...

Retrieving an Array in CakePHP Through an Ajax Post Request

Despite the countless other 'duplicate' questions on this topic, I still find myself stuck. My goal is simply to log an array passed from PHP via ajax. In CakePHP 2.X: In View: <button class="quarter q1" value="1" value>Quarter 1</but ...

Modify the css of the initial div following a live click

After clicking on the span.submit-comment, I am looking to modify the CSS of a specific div. Can anyone advise me on how to achieve this? I attempted to change the background color of the div in the success section of the script like so: $('div.new ...

Is there a way to convert the data into percentile values?

In my current project, I am dealing with a sample total users of 20. When I use console.log((acc[month] / totalUsers) * 100);, it correctly displays the percentage as 15. However, when trying to represent this data on a chart, the numbers appear incorrect. ...

Implementing the style tag within a view

In my exploration of various Razor views, I've noticed a common practice where developers include a <style> tag directly in the CSHTML file. While this method may seem to work without issue, it actually places the <style> tag within the & ...

Instructions for using Selenium to access the "stats for nerds" option on a YouTube video by right-clicking

I am currently working on a program that has the ability to block YouTube ads and keep track of the blocked Ad Video IDs. To achieve this, our selenium program needs to simulate a right click on the video to open the video menu and then select "stats for ...

Limit user input in TextField to positive unsigned integers using ReactJS Material-UI

I'm working on an input field that should only allow positive integers, without accepting characters like - + , or .. <TextField fullWidth type="number" placeholder={'[1-100]'} id="simple-start-adornmhent" onChange={this.handle ...

The checkbox remained unchanged when I first tried to toggle it using ng-change

When I click on the checkbox input, nothing happens the first time. But when I click it again the function in ng-change() works as expected. I am confused. Am I missing something? <tr dir-paginate="product in kitchenProducts | itemsPerPage: 10"> ...