Remove["Global`*"]
ode[u_, x_] := D[u[x], x] - u[x]
DSolve[{ode[u, x] == 0, u[0] == 1}, u[x], 
      x]
Plot[u[x] /. %, {x, 0, 1}]

q = Array[a, 4];
q[[1]] = 1;
length = 1;
nEle = 3;
nNodes = nEle + 1;
dx = (length/nEle);
x0 = 0;
x1 = x0 + dx;
x2 = x1 + dx;
x3 = x2 + dx;

NN0[x_]:=If[x0 < x ≤ x1,((x1-x)/(x1 - x0)),0];
NN1[x_]:=If[x0 ≤ x ≤ x1,((x-x1)/(x1 - x0)),0];
NN2[x_]:=If[x1 ≤ x ≤ x2,((x2-x)/(x2 - x1)),0];
NN3[x_]:=If[x1 ≤ x ≤ x2,((x-x1)/(x2 - x1)),0];
NN4[x_]:=If[x2 ≤ x ≤ x3,((x3-x)/(x3 - x2)),0];
NN5[x_]:=If[x2 ≤ x ≤ x3,((x-x2)/(x3 - x2)),0];

shapeFunction = {NN0, 
        NN1, NN2, NN3, NN4, NN5}
globalTrial[x_] := 
      Sum[q[[j + 
                1]] shapeFunction[[2  
                    j + 1]][x]  + 
          q[[j + 
                2]] shapeFunction[[2  
                    j + 2]][x], {j, 0, 2}]

residual = ode[globalTrial, x]

eqs = 
      Table[Integrate[(shapeFunction[[2 i + 1]][
                  x] + shapeFunction[[2 i + 2]][x]) residual, {x, 
            0, 1}], {i, 0, 2}]

residual

Integrate[(shapeFunction[[1]][x] + shapeFunction[[2]][
              x]) residual, {x, 0, 1}]
Integrate[(shapeFunction[[2]][x]), {x, 0.  ..  01, 
        1}]

coeff = 
      Solve[eqs, {q[[2]], q[[3]], 
          q[[4]]}]
q[[2]] = coeff[[1, 1, 2]]
q[[3]] = coeff[[1, 2, 2]]
q[[4]] = coeff[[1, 3, 2]]
Plot[globalTrial[x], {x, 0, 1}]

eqs

(q[[0 + 
              1]] 
          shapeFunction[[2 0 + 1]] /. 
        x ->  .1  + 
            q[[0 + 
                  2]] shapeFunction[[2 0 + 2]][x])

globalTrial[x]

?If

foo[x_]:=Module[{},
If[x0 ≤ x ≤ x1,Return[0],Return[(((Subscript[x, 1])-x)/((Subscript[x, 1]) - (Subscript[x, 0])))]];
];
x0 = 
        0;
x1 =  .33;
x =  .1;
foo[
      x]

globalTrial[ .4]

residual

coeff[[1, 3, 2]]

x1

ode[u, x]

ode[globalTrial, x]

coeff

coeff

ode[globalTrial, x]

D[shapeFunction[[2]][x], x]