I'm trying to figure out if this application of the != operator is valid for the FizzBuzz problem. Here's my code:
function fizzBuzz(num){
if(num==3%0 && num!=5%0){
return("Fizz");
}
else if(num==5%0 && num!=3%0){
return("Buzz");
}
else if(num==5%0 && num==3%0){
return("FizzBuzz")
}
}
else {
return(num);
}
Related
I'm creating an if/else statement that is based on if certain cookies exist, but when I run the code it just gives out: 1000, 1000.
Note: I'm using a cookie plugin too at https://github.com/js-cookie/js-cookie.
Here's the javaScript (only a small part of the actual code):
Cookies.get("options");
Cookies.get("options2");
if (Cookies.get('options'&& 'options2') == '1000', '1000') {
alert("1000, 1000");
} else if (Cookies.get('options') && Cookies.get('options2') == '1100', '1000') {
alert("1100, 1000");
} else if (Cookies.get('options') && Cookies.get('options2') == '1010', '1000') {
alert("1010, 1000");
} else if (Cookies.get('options') && Cookies.get('options2') == '1001', '1000') {
alert("1001, 1000");
} else if (Cookies.get('options') && Cookies.get('options2') == '1110', '1000') {
alert("1110, 1000");
} else {
}
I believe the issue is the following line:
if (Cookies.get('options'&& 'options2') == '1000', '1000') {
Working with two values doesn't work the way you seem to be trying. I would try something like this:
if (Cookies.get('options') == '1000' && Cookies.get('options2') == '1000') {
This is because Cookies.get() only accepts one cookie name at a time and returns the value for that one cookie, and you have to do each comparison separately.
i am validating a form and then asking for the confiormation through javascript…
so on submit i have called two function name validate() & make_confirm()..
onsubmit="return(validate() && show_alert(this));"
by this i am partially able to call both function but confirmation part is not working fine i have to redirect it to another page while pressing OK but its not going please help me out
validate & make_sure() function is as like:
function validate() {
if(document.getElementById('cname').value == '')
{
alert('Please enter your name');
document.getElementById('cname').focus();
return false;
}
else if(document.getElementById('address').value == '')
{
alert('Please enter your address');
document.getElementById('address').focus();
return false;
}
else if(document.getElementById('city').value == '')
{
alert('Please choose your city');
document.getElementById('city').focus();
return false;
}
else if(document.getElementById('state').value == '')
{
alert('Please enter your state');
document.getElementById('state').focus();
return false;
}
function make_sure() {
if(confirm("Do you really want to do this?"))
document.forms[0].submit();
else
return false;
}
Use one function for validate and confirm and set action of form to redirect form current page to another page.
function validateAndConfirm() {
if( isEmpty(id('cname').value) ) {
alert('Please enter your name');
id('cname').focus();
return false;
}
else if( isEmpty(id('address').value) ) {
alert('Please enter your address');
id('address').focus();
return false;
}
else if( isEmpty(id('city').value) ) {
alert('Please choose your city');
document.getElementById('city').focus();
return false;
}
else if( isEmpty(id('state').value) ) {
alert('Please enter your state');
id('state').focus();
return false;
} else {
if(confirm("Do you really want to do this?")) {
document.forms[0].submit();
}
else {
return false;
}
}
}
function isEmpty(val){
return (typeof val == 'undefined' || val === undefined || val == null || val.length <= 0) ? true : false;
}
// this function help to simplify you writing : document.getElementById to just id
function id(sid){
return document.getElementById(sid);
}
I'm trying to get a formula scripted properly, can some one help me please. I'm using Birt 3.7.1. thanks. This is for a Maximo report
if(row["special"] == 'W' && row["metername"] == null){
false} *** I need this coded --don't hide --> must have a task ***
else{
true}
if(row["special"] == 'W' && row["metername"] != null){
false} *** I need this coded --don't hide --> must have task --> view ***
else if(row["special"] == 'W' true
else true}
I'm not entirely sure what you're asking here, but if you're looking to just get your code here formatted validly, here you go:
if (row["special"] == 'W' && row["metername"] == null) {
return false;
} else {
return true;
}
if (row["special"] == 'W' && row["metername"] != null) {
return false;
} else if (row["special"] == 'W') {
return true;
} else {
return true;
}
I'm not sure its the most practical code, but there you go.
I have 2 simple JS function one checks values of 2 input fields and triggers the other function Here is the code
function ValidateForm()
{
var name = document.getElementById('fullname').value;
var email = document.getElementById('email').value;
if(name.value= '' || email.value='')
{
alert('fields Empty');
}
else
{
UpdateRecord();
}
}
function UpdateRecord()
{
var Qact = getQueryVariable('ACT');
if(Qact==2){
var picture= document.getElementById('myPic').src;
activity.setUpdates(name,email,picture);
}
else
{
activity.CheckEmail(name,email);
}
}
HTML
<button onClick="ValidateForm();" data-role="button" >Register</button>
if I call UpdateRecord() on button click it works fine but when i use ValidateForm() nothing works. The firefox debugger don't even go to the ValidateForm() Function
if(name.value= '' || email.value='')
should be
if(name === '' || email === '')
if(name.value== '' || email.value=='')
{
alert('fields Empty');
}
else
{
UpdateRecord();
}
Try this to compare values:
if(name.value == '' || email.value == '')
{
alert('fields Empty');
}
else
{
UpdateRecord();
}
I have PHP and JS script for uploading image. PHP file returns a var err:type and I'm checking in JS if return == err:type, but it doesn't work.
$(document).ready
(
function()
{
$('#avatar_image_upload_form').submit
(
function()
{
$('div#avatar_ajax_upload_demo img').attr('src','../../Files/Border/loading.gif');
}
);
$('iframe[name=avatar_upload_to]').load(
function()
{
var result = $(this).contents().text();
if(result !='')
{
$('div#avatar_ajax_upload_demo img').attr('src',result);
if(result == 'err:size')
{
$('div#avatar_ajax_upload_demo img').attr('src','../../Files/Border/avatar_big.jpg');
}
if (result == 'err:type')
{
$('div#avatar_ajax_upload_demo img').attr('src','../../Files/Border/avatar_invalid.jpg');
}
}
}
);
}
);
if(result == 'err:type') doesn't work, but result = "err:type"
According to this image:
There are a lot of white lines at the beginning of the string. You need to trim the result string to remove them:
var result = $(this).contents().text().trim();
You should best fix your PHP code in order not to send those blank lines.
[WRONG]
Maybe your error is here : (if avatar_upload_to isn't a variable)
$('iframe[name=avatar_upload_to]').load(
Should be
$('iframe[name="avatar_upload_to"]').load(
=====
[TEST]
What appends if you make this :
$('iframe[name=avatar_upload_to]').load(
function()
{
var result = $(this).contents().text();
console.log(result);
//or
alert(':'+result+':');
if(result !='')
{
$('div#avatar_ajax_upload_demo img').attr('src',result);
if(result == 'err:size')
{
$('div#avatar_ajax_upload_demo img').attr('src','../../Files/Border/avatar_big.jpg');
}
if (result == 'err:type')
{
$('div#avatar_ajax_upload_demo img').attr('src','../../Files/Border/avatar_invalid.jpg');
}
}
}
);