Basic JS methods not recognized?

Working on my first javascript program so bare with me :)

Error on both red methods is "Cannot resolve method..." but they seem rather basic javascript methods? (see first screenshot)

I already tried the following.

  • I tried the "File | Invalidate Caches / Restart" opton, no solution.
  • I reinstalled IntellJ Idea (and wen't so version 2019.2, no solution
  • I think i got the jdk installed correctly (see second screenshot)

How do I get this basic javascript methods working?

TIA

ABBOV.

 

0
5 comments

Sorry, but this is Java code, not JavaScript? and you are editing .java file, aren't you?

Try changing your code as follows:

List list = new ArrayList<>();
for (int team : allTeams) {
list.add(team);
}

if (!(list.contains(teamNr))) {
System.out.println("nothing found");
list.add(teamNr);
}
0
Avatar
Permanently deleted user

Hi Elena,

Thanks for your aswer, unforetunaly this gives me sort of the same error? here the 'contains' method is also not recognized. I trying this because of the fact that I'm not getting the the named objects to work?

What I realy would like to do is to create an array, filled with objects whicht contains multiply datatypes, something like this:

public void teamAanmaken() {
int teamNr;
String inOut;
int postNr;
String date;
var allTeams = [
{teamNr: 101, inOut: "IN", postNr: 1, date: "31-07-2019, 22:13"}
{teamNr: 101, inOut: "OUT", postNr: 1, date: "31-07-2019, 22:25"}
{teamNr: 102, inOut: "IN", postNr: 1, date: "30-07-2019, 17:45"}
{teamNr: 301, inOut: "IN", postNr: 2, date: "30-07-2019, 18:45"}
];

Is this something that is possible? I found this piece of code online but it does not seem to work in IntelIJ ?

 

 

0

>here the 'contains' method is also not recognized

 

it is recognized for me. Did you import the java.util.*? What does your class look like? Please provide a complete code snippet

 

Your

var allTeams = [{}]

is a JavaScript code, what makes you think that adding it to java method can work?

0
Avatar
Permanently deleted user

Hi Elena,

Here's my total code, please bare with me, these are my first steps on javascripting. :)
At this moment purely based on the console, no HTML yet.

import java.util.Date;
import java.util.Scanner;

public class ProgrammaHikeTracker {

private boolean postBekend = false;
private int postNr;
private String inOut = "In";

public int menu(){

Scanner myScanner = new Scanner(System.in);
if(postBekend == false){
System.out.println("█████████████████████████████████");
} else{
System.out.println("█████████████ Post " + postNr + " ████████████");
}
System.out.println("█ Menu █");
System.out.println("█ 1. Aanmaken team █");
if(postBekend == false){
System.out.println("█ 2. Post selecteren █");
} else {
System.out.println("█ 2. Andere post selecteren █");
}
if(postBekend == false){
System.out.println("█ █");
} else {
System.out.println("█ 3. Aanmelden op post █");
}
if(postBekend == false){
System.out.println("█ █");
} else {
System.out.println("█ 4. Afmelden op post █");
}
System.out.println("█ █");
System.out.println("█ 6. Team overzicht █");
System.out.println("█ 7. Post overzizht █");
System.out.println("█ █");
System.out.println("█████████████████████████████████");
System.out.println(" ");
System.out.println("Geef je keuze op: ");
int menuKeuze = myScanner.nextInt();
return menuKeuze;
}

public int teamNummer(){
// Uitvragen team nummer.
int teamNr;
Scanner myScanner = new Scanner(System.in);
System.out.println("Geef je teamnummer op");
teamNr = myScanner.nextInt();
return teamNr;

}
public int postNummer(){
// Uitvragen post nummer.
Scanner myScanner = new Scanner(System.in);
System.out.println("Welke post beman je? ");
postNr = myScanner.nextInt();
postBekend = true;
return postNr;
}

public void teamAanmaken() {

int teamNr;
String inOut;
int postNr;
String date;
var allTeams = [
{teamNr: 101, inOut: "IN", postNr: 1, date: "31-07-2019, 22:13"}
{teamNr: 101, inOut: "OUT", postNr: 1, date: "31-07-2019, 22:25"}
{teamNr: 102, inOut: "IN", postNr: 1, date: "30-07-2019, 17:45"}
{teamNr: 301, inOut: "IN", postNr: 2, date: "30-07-2019, 18:45"}
];

/*
int[] allTeams = {101, 102, 103, 104, 105, 201, 202, 203, 301, 302, 303}; // make dynamic later on
int teamNr;

Scanner myScanner = new Scanner(System.in);
System.out.println("Geef je teamnummer op");
teamNr = myScanner.nextInt();
// check of teamnummer voorkomt in array
if (boolean n = allTeams.includes(teamNr) == false;) {
System.out.println("Team bestaat al.");
}
allTeams.push(teamNr);
*/
}

public void teamAanmelden() {
// Aanmelden op post
int sessieTeam = teamNummer(); // uitvragen team nummer
// controleren of postnr al 'ingeladen' is, zo niet, dan vragen om postnummer.
if(postBekend == false){
int postNr = postNummer();
}
inOut = "IN";
// wegschrijven aanmelding
String aanmeldRegel = sessieTeam + ", " + inOut + ", " + postNr + ", " + new Date();
System.out.println(aanmeldRegel);
};

public void teamAfmelden() {
// afmelden op post
int sessieTeam = teamNummer(); // uitvragen team nummer
if(postBekend == false){
int postNr = postNummer();
}
inOut = "UIT";
// wegschrijven afmelding
String aanmeldRegel = sessieTeam + ", " + inOut + ", " + postNr + ", " + new Date();
System.out.println(aanmeldRegel);
};

public void run () {
// Begin van code
boolean menuActief = true;
while(menuActief = true){ // altijd terug naar menu.
int menuKeuze = menu();
if (menuKeuze == 1) {
//teamAanmaken();
}
if (menuKeuze == 2) {
postNummer();
}
if (menuKeuze == 3) {
teamAanmelden();
}
if (menuKeuze == 4) {
teamAfmelden();
}
if (menuKeuze == 5) {
// leeg
}
if (menuKeuze == 6) {
// Team overzicht
}
if (menuKeuze == 7) {
//Post overizcht
}
}
}
// Einde van code

public static void main(String[] args) {
// aanroepen
new ProgrammaHikeTracker().run();
}
}
0

>Here's my total code, please bare with me, these are my first steps on javascripting. 

This is (mostly) Java, NOT JavaScript!!!

var allTeams = [{}] is JavaScript, everything else is Java. You can't mix both.

Before moving on, let's decide on a language your are going to use, environment, things you are going to accomplish, etc.

0

Please sign in to leave a comment.